Skip to content
Snippets Groups Projects
Unverified Commit 8449f8a2 authored by briancanini's avatar briancanini Committed by GitHub
Browse files

Merge pull request #404 from ASCWebServices/scripts2

Add query_all.sh and which_sites_use_module.sh
parents 1b7072c7 38da58b8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
# if [[ -z `which parallel` || -z `which tmux` || -z `which gdate` ]]; then
# echo "Either 'parallel' or 'tmux' is not installed...";
# if [[ -z `which brew` ]]; then
# echo "Homebrew is NOT installed. Homebrew needs to be installed to proceed.";
# echo "Visit https://https://brew.sh/ for more information.";
# exit 1;
# else
# echo "Attempting to install parallel, tmux, coreutils...";
# brew install parallel tmux coreutils;
# fi
# fi
# Example usage:
# echo "select distinct type, count(*) from node group by 1 order by 2 desc;" > node_counts.sql
# ./query_all.sh node_counts.sql live | tee node_counts.txt
UPSTREAM='b9baf7af-eb2c-4db5-81e6-32d3d9042572';
# Check command line arguments
if [[ -z $1 ]]; then
echo; echo "Usage: $0 \"query\"";
echo; echo "Usage: $0 <query_file> [environment]";
echo; echo;
exit 1;
elif [[ ! -f $1 || ! -r $1 ]]; then
echo; echo "The filename '$1' doesn't exist, isn't readable, or isn't an ordinary file.";
echo; echo;
exit 1;
fi
# Default to 'dev' environment if none was specified
if [[ -z $2 ]]; then
echo; echo "No environment specified, assuming dev.."; echo;
ENV='dev';
else
ENV=$2;
fi
mysql-pantheon ()
{
if [[ -z $1 ]]; then
echo "Usage: mysql-pantheon <site.env>";
echo;
return;
fi;
terminus env:wake $1;
`terminus connection:info --fields=mysql_command --format=string $1;`
}
# ENV=$1;
# shift;
# if [[ $ENV == 'test' || $ENV == 'live' ]]; then
# if [[ -z $1 ]]; then
# while [[ -z $DEPLOY_MSG ]]; do
# echo;
# read -p "Enter deployment message: " DEPLOY_MSG;
# echo;
# done
# else
# DEPLOY_MSG=$@;
# fi
# fi
# NOW=`date +%Y%m%d_%H%M`;
# LOG_DIR="deploy-$ENV-$NOW";
# mkdir $LOG_DIR;
# echo "LOG_DIR: $LOG_DIR";
export -f mysql-pantheon;
SITES=$(terminus org:site:list ohio-state-arts-and-sciences --upstream=b9baf7af-eb2c-4db5-81e6-32d3d9042572 --fields=name --format=string | sort);
parallel --tag "echo \"$1\" | mysql-pantheon {}.live" ::: $SITES
# for site in $SITES; do
# echo "=== $site ===";
# # echo "select nid, cid, name from webform_component where type = 'file' and extra like '%html%';" | `terminus connection:info --fields=mysql_command --format=string ${site}.live;`
# echo "$1" | mysql-pantheon ${site}.live;
# We use a second "inner script" because we prefer to use GNU 'parallel' for speed if it's available, and I can't
# figure out how to run a multi-command subprocess with parallel without putting it in a second script.
INNER_SCRIPT='./query_site.sh';
# echo;echo;
# done
# Check $INNER_SCRIPT exists and is executable
if [[ ! -f $INNER_SCRIPT || ! -x $INNER_SCRIPT ]]; then
echo; echo "'$INNER_SCRIPT' isn't an executable script. Stopping.";
echo; echo;
exit 1;
fi
# parallel --delay 0.1 --tag "terminus remote:drush {}.live pmi $1 -- --format=table --fields=status,extension --no-field-labels 2>/dev/null" ::: $SITES
# echo $SITES | parallel --delay 0.1 "terminus remote:drush {prohibition}.live pmpi piwik_reports -- --format=table --fields=status,name --no-field-labels 2>/dev/null";
# ALL sites
echo "Get sites...";
SITES=$(terminus site:list --upstream=$UPSTREAM --fields=name --format=string | sort);
echo $SITES;
# Non-sandbox sites only
# SITES=$(terminus site:list --upstream=$UPSTREAM --fields=name --format=string --filter=plan_name!=Sandbox | sort);
# parallel --delay 0.1 --tmuxpane --fg -a $LOG_DIR/site_list.txt "scripts/deploy-site-env.sh {}.$ENV $DEPLOY_MSG 2>&1 | tee $LOG_DIR/{}.log";
# Check for GNU parallel
USE_PARALLEL=false;
PARALLEL_PATH=$(which parallel); # 'parallel' command exists
echo "'parallel' path: $PARALLEL_PATH";
# echo; echo; echo "Sleeping for 11 seconds..."; echo; echo;
# sleep 11;
if [[ ! -z $PARALLEL_PATH ]]; then
PARALLEL_VERSION=$($PARALLEL_PATH --version); # get version
echo "'parallel' version: $PARALLEL_VERSION";
if [[ $PARALLEL_VERSION == *"GNU parallel"* ]]; then
echo "GNU parallel found: $PARALLEL_PATH";
USE_PARALLEL=true; # it really is GNU parallel. we like it.
fi
fi
# reset;
# wait;
if [[ "$USE_PARALLEL" == true ]]; then
# With parallel
parallel --delay 0.1 --tag "$INNER_SCRIPT {}.$ENV $1" ::: $SITES
else
# We're going to use the inner script even without parallel
# because DRY and I can't be bothered to update the logic in 2 places.
# cd $LOG_DIR;
# wc -l * | sort -n | tee line-counts.txt;
# cd ..;
for SITE_NAME in $SITES; do
echo "=== $SITE_NAME ===";
$INNER_SCRIPT $SITE_NAME.$ENV $1;
echo;echo;
done
fi
# echo; echo; echo "Sleeping for 11 more seconds..."; echo; echo;
# sleep 11;
#!/usr/bin/env bash
if [[ -z $1 ]]; then
echo; echo "Usage: $0 'module_name'";
echo; echo;
exit 1;
fi
LOG_FILE=$1-sites-`date +%Y%m%d_%H%M`.txt;
echo "log file: $LOG_FILE"; echo;
SITES=$(terminus org:site:list ohio-state-arts-and-sciences --upstream=b9baf7af-eb2c-4db5-81e6-32d3d9042572 --fields=name --format=string | sort);
parallel --delay 0.1 --tag "terminus remote:drush {}.live pm:list -- --format=table --fields=status,name |grep $1" ::: $SITES | tee $LOG_FILE
ENABLED_COUNT=$(grep -i 'enabled' $LOG_FILE | wc -l);
DISABLED_COUNT=$(grep -i 'disabled' $LOG_FILE | wc -l);
UNINSTALLED_COUNT=$(grep -i 'not installed' $LOG_FILE | wc -l);
# perl -pi -e 's/^[-\w]+\s+enabled\s+\w+\s*\n//;' $LOG_FILE;
# perl -pi -e 's/^[-\w]+\s+disabled\s+\w+\s*\n//;' $LOG_FILE;
# perl -pi -e 's/^[-\w]+\s+not installed\s+\w+\s*\n//;' $LOG_FILE;
echo;
if [ -s $LOG_FILE ]; then
echo; echo "====================================";
cat $LOG_FILE;
echo "====================================";echo;
else
echo "Pruned log file is empty. Deleted."; echo;
# rm $LOG_FILE;
fi
echo "$ENABLED_COUNT - enabled.";
echo "$DISABLED_COUNT - disabled.";
echo "$UNINSTALLED_COUNT - not installed.";
echo;echo;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment