Skip to content

Instantly share code, notes, and snippets.

@mccun934
mccun934 / gist:879cefe4ce6cd39e70fe8058e8bca2a2
Created May 15, 2019 21:48
postgres settings without comments or whitespace
cat postgresql.conf |awk '{$1=$1};1' |grep -v "^#" | egrep -v "^[ ]*$|^#" |more
@mccun934
mccun934 / gist:b25876d81d8940be1f758370b84b4e30
Created March 28, 2019 17:17
Sequel::Migrator::Error: More than 1 row in migrator table
# foreman-rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
TABLE dynflow_schema_info
rake aborted!
Sequel::Migrator::Error: More than 1 row in migrator table
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/extensions/migration.rb:590:in `schema_dataset'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/extensions/migration.rb:444:in `initialize'
@mccun934
mccun934 / mem-process-sum
Created March 25, 2019 16:26
sum up the ram used by all processes with a given name.
#!!bin/bash
# requires 'bc' installed
# Sum up the RAM used by processes with given name
# eg:
# $ mem-process-sum postgres
# 1.6777 GB
ps aux | sort -nk6 |grep $1 | awk '{print $6}' | paste -sd+ | bc | awk '{$1=$1/(1024^2); print $1,"GB";}'
@mccun934
mccun934 / publish-loop.bash
Created March 16, 2019 14:36
republish all content views in a loop
while true;
do
hammer --no-headers --csv content-view list | grep -v "Default Org" | awk -F, '{print $1}' | xargs -I arg1 -n 1 hammer -u admin -p changeme content-view publish --id arg1;
done
## Logging
ErrorLog "/var/log/httpd/foreman-ssl_error_ssl.log"
ServerSignature Off
CustomLog "/var/log/httpd/foreman-ssl_access_ssl.log" combined
# Add custom forwarded log to track origin IP addresses through a smart-proxy
CustomLog "/var/log/httpd/foreman-ssl_forwarded_ssl.log" forwarded
#!/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 root@xxx.xxx.xxx.xxx:/ /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 (