Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
echo "Refreshing repository certificates."
echo '
organizations = Organization.all
organizations.each do |org|
repositories = ::Katello::Repository.in_default_view.in_product(::Katello::Product.redhat.in_org(org))
repositories.each do |repo|
task = ForemanTasks.async_task(Actions::Katello::Repository::RefreshRepository, repo)
./app/lib/actions/katello/organization/manifest_refresh.rb
module Actions
module Katello
module Organization
class ManifestRefresh < Actions::AbstractAsyncTask
middleware.use Actions::Middleware::PropagateCandlepinErrors
def plan(organization)
action_subject organization
manifest_update = organization.products.redhat.any?
echo "select usesysid,usename,state,waiting,query from pg_stat_activity where state = 'active'" | sudo -u postgres psql
@mccun934
mccun934 / sshfs.bash
Last active January 23, 2019 17:06
sshfs example
curl https://mirrors.rit.edu/fedora/epel/7/x86_64/Packages/f/fuse-sshfs-2.10-1.el7.x86_64.rpm > fuse-sshfs-2.10-1.el7.x86_64.rpm
yum -y install fuse-sshfs-2.10-1.el7.x86_64.rpm
mkdir /mnt/remote
sshfs -o allow_other [email protected]:/ /mnt/remote
@mccun934
mccun934 / postgres-tablesizes.bash
Created December 11, 2018 15:44
postgres tablesizes
#!/bin/bash
TABLEQUERY=$(cat <<-END
SELECT table_name, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
@mccun934
mccun934 / httpd access log rate commands.md
Last active October 24, 2018 21:22
Httpd log rate commands
SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS SIZE
FROM pg_catalog.pg_database d
ORDER BY
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_database_size(d.datname)
ELSE NULL
@mccun934
mccun934 / mongodb_collection_sizes.js
Last active August 13, 2018 17:50 — forked from joeyAghion/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
#!/bin/bash
systemctl stop foreman-tasks.service
cat <<EOF | foreman-rake console
User.current = User.anonymous_admin
ForemanTasks::Task.where(:label => "Actions::Candlepin::ListenOnCandlepinEvents").destroy_all
ForemanTasks::Task.where(:label => "Actions::Katello::EventQueue::Monitor").destroy_all
EOF
systemctl start foreman-tasks.service
#!/usr/bin/env ruby
require 'yaml'
require 'oauth'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
katello_config = YAML.load_file('/etc/foreman/plugins/katello.yaml')
consumer_key = katello_config[:katello][:candlepin][:oauth_key]
consumer_secret = katello_config[:katello][:candlepin][:oauth_secret]