Hello , welcome to Castle-Murray
Login Register

sean has made 10 posts.

Is it pointed here? L:1 | C:1
Date posted: Nov. 29, 2022, 3:35 a.m.
Problem: Need to know what is pointe here? Apart from proxied stuff like cloudflare
What does it do?: checks all domains on the server against each of the dedicated ips.
sean@castle-murray.com[~/bash/uapi] #
checkdomains() { 
domnip=$(awk -F ": " '!/*/ {system(" echo " $1 " $( dig +short " $1 ")")}' /etc/userdomains)
for ip in $(hostname -I | sed s/127.0.0.1//) 
do echo "$domnip" | grep $ip
done 
}
checkdomains
page load size L:1 | C:1
Date posted: Nov. 29, 2022, 2:45 a.m.
Problem: page loading slowly. Hitting I/O limit on page loads?
What does it do?: find how much data is being loaded by an index.php file
sean@castle-murray.com[~/bash/php] #
strace_index(){
touch results.txt
strace -o results.txt -ttfe trace=open php index.php 2&>1 /dev/null
files=$(awk -F "\"" '!/No such file/ && /open/ && /home/ {print $2}' results.txt)
echo -e "\n\t Loading $(echo "${files}" | wc -l) files."
echo -e "\n\t $(echo "${files}" | xargs du -k | awk '{sum+=$1;} END{print sum;}') KB total.\n"
rm -rf results.txt
}
strace_index
Database creator. L:1 | C:0
Date posted: Nov. 27, 2022, 12:05 a.m.
Problem: need a databse, don't want to leave cli.
What does it do?: creates a database in the cPanel with a user and full privileges. Takes a suffix and creates a random password.
sean@castle-murray.com[~/uapi/cpanel/bash] #
(
read -p "Database suffix: " sfx
pfx=$(uapi Mysql get_restrictions|awk '/prefix/ {print $2}')
name="${pfx}${sfx}"
pw=$(head /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c15)
uapi Mysql create_database name="${name}"
uapi Mysql create_user name="${name}" password="${pw}"
uapi Mysql set_privileges_on_database user="${name}" database="${name}" privileges=ALL
echo "Database and user name: "${name}""
echo "password: "${pw}""
unset pw
)
Fix wp-config L:2 | C:2
Date posted: Nov. 27, 2022, midnight
Problem: blank returns from wp-cli
What does it do?: takes the db info from a wp-config file and generates a new one.
sean@castle-murray.com[~/wp-cli] #
fix-wp-config(){ if grep 'database_name_here' wp-config.php; then echo "no valid db info to copy"; else dbname=$(awk -F "'" '/DB_NAME/ {print $4}' wp-config.php); dbuser=$(awk -F "'" '/DB_USER/ {print $4}' wp-config.php); dbpass=$(awk -F "'" '/DB_PASSWORD/ {print $4}' wp-config.php); dbhost=$(awk -F "'" '/DB_HOST/ {print $4}' wp-config.php); prefix=$(awk -F "'" '/table_prefix/ {print $2}' wp-config.php); mv wp-config.php{,-$(date -I)}; wp config create --dbname="${dbname}" --dbuser="${dbuser}" --dbpass="${dbpass}" --dbprefix="${prefix}" --dbhost="${dbhost}"; fi; }; fix-wp-config
Large file finder L:1 | C:0
Date posted: Nov. 26, 2022, 11:51 p.m.
Problem: no disk space
What does it do?: find large files
sean@castle-murray.com[~/bash/cpanel] #
(
job(){ width=$((`tput cols`-`echo $1|wc -m`))
offset=$(($width/2))
col=1
while [ $col -lt $offset ]
do echo -n " "
col=$(($col+1))
done
echo -e "$1"
 }
LargeFileLocator(){ task(){ echo "=> $1"
echo
 }
check(){ if [ -z $1 ]
then dir=$(pwd)
fi
if [ -d $1 ]
then if [ `ls $1|wc -l` -gt 0 ]
then cd $1
if [ -z `ls|grep -v "-"|du -h|grep '[0-9]G'|head -1|awk {'print $1'}` ]
then echo -e "\tALL LOOKS GOOD IN HERE. ($1)"
echo
else du -m --max-depth=3|sort -nr|cut -f2|tr \\n \\0|xargs -0 du -sh|sed 's/.\///'|grep -v '[0-9]M\|[0-9]K'|awk -v wd="$(pwd)" '{print wd"/"$2" "$1}'|sort|awk '{print "ATTENTION: "$2" found  ==>  "$1}'|sed 's/^/\t    /'|sed 's/\/\.//'
echo
fi
else echo -e "\tNOTHING FOUND IN HERE. ($1)"
echo
fi
else echo -e "\tNOTHING FOUND HERE. ($1)"
fi
 }
clear
echo
job "LARGE FILE/FOLDER LOCATOR"
echo
job "`df -h|sed '1d'|grep -v "none\|udev\|tmp"|awk -v svr=$(hostname|cut -d\. -f1) '{print "Currently "$3"("$5") of "$2" used."}'`"
job "`df -h|sed '1d'|grep -v "none\|udev\|tmp"|awk -v svr=$(hostname|cut -d\. -f1) '{print $4" of free space is left on "svr}'`"
echo
echo
task "Checking for large orphaned files in home dir:"
if [ -z `ls -lah /home |awk {'print $9'}|sed '1,3d'|grep -v "-"|grep -v "......[0-9]"|xargs -I {} du -smh "/home/"{}|grep -o '[0-9]G'|head -1` ]
then echo -e "\tALL LOOKS NORMAL IN HERE. (/home)"
echo
else check "/home"|grep -vw "`echo $(cat /etc/trueuserdomains|awk '{print "/home/"$2}')|sed -e '1,10s/ /.*$\\\|/g'`"|sed '/^.*home$/d'
fi
task "Looking for large cPanel user folders:"
for user in `cat /etc/trueuserdomains | awk '{print $2}'`
do if [ `du -ms "/home/"$user|cut -f1` -gt 1000 ]
then echo -e "\tcPanel User $user seems pretty large..."
check "/home/$user"
fi
done
task "Checking for large standard log files:"
check "/var/log"
task "Looking for large mysql db's & logs:"
check "/var/lib/mysql"
task "Looking for large WHM (scheduled) backups:"
check "/backup"
echo
 }
st=`date +%s`
LargeFileLocator
et=`date +%s`
job "DONE"
job "(Execution Time: `expr $et - $st`s)"
echo
)
First Previous 2