Script to Kill MySQL Sleeping Processes

Create Script /bin/mysql_kill_sleepProc.sh #!/bin/bash echo ” ” echo ‘###########################################’ date mysqladmin -u root –password=<mysqlPassword> processlist|grep Sleep for i in `mysqladmin -u root –password=<MysqlPASSWORD> processlist|grep Sleep|awk ‘{print $2}’`; do mysqladmin -u root –password=<MysqlPASSWORD> kill $i; done > /dev/null 2>&1 wc=`echo $?` if test $wc == 0 then echo “Mysql sleeping queries killed succesfully” else echo “Command…

Bash Scripting – TRAP

Many of us might have faced a stiuation where we have started a script, waiting for its outcome and suddenly someone/ourself do a CTRL+C by mistake to terminate the script. Wouldn’t it be nice if our script becomes ‘immune’ to CTRL+C signal. Here comes ‘trap’ command for help. ‘trap’ command basically traps the signal which…

Playing with awk

smbstatus -S 2>/dev/null|awk ‘BEGIN{FS=" ";OFS=" ";}{$2=""; print $0;}’|awk ‘{print $1,"         ",$2,"         ",$3,$4,$5,$6,$7}’ –> Above command will hide column 2 and will give you below output: Service           machine           Connected ——————————————————-         For hiding above lines … to just get only service name – mahine name – connected… –> smbstatus -S 2>/dev/null|awk ‘BEGIN{FS=" ";OFS="   ";}{$2=""; print $0;}’|awk ‘{print…