오후 7시 까지만 수행 되고 종료 되는 쉘 스크립트
check_sess.sh
#!/bin/sh #hm=`date +"%H%M"` #echo $hm #This shell terminated at 19:00 while true do clear echo " " date +"%m-%d %T" echo " " hm=`date +"%H%M"` if [ $hm -eq 1900 ] then break fi echo "SELECT TOT.cnt 'TOTAL' , ACT.cnt 'ACT' FROM ( SELECT count(*) cnt FROM information_schema.processlist ) TOT , ( SELECT count(*) cnt FROM information_schema.processlist WHERE command != 'Sleep') ACT ;" | /mysql/local/mysql/bin/mysql -uroot -pabcdef sleep 5 done echo " " echo "Time to go home. " echo " " |
단순히 위에 것만 하니깐 실제 active 증가 시점에 다시 작업이 이루어져야 해서 …
Active Session이 20개 이상이면 자동으로 로깅을 하게 함.
#!/bin/sh mv /home/scripts/act/act.out /home/scripts/act/act.bak while true do hm=`date +"%H%M"` if [ $hm -eq 1900 ] then break fi cnt=`echo "SELECT count(*) cnt FROM information_schema.processlist WHERE command not in ('Sleep' , 'Binlog Dump') ;" | /mysql/local/mysql/bin/mysql -uroot -pabcdef -s` if [ $cnt -gt 20 ] then echo " " >> /home/scripts/act/act.out echo " " >> /home/scripts/act/act.out date +"%m-%d %T" >> /home/scripts/act/act.out echo "SELECT * FROM information_schema.processlist WHERE command not in ('Sleep' , 'Binlog Dump') AND id != connection_id() ;" | /mysql/local/mysql/bin/mysql -uroot -pabcdef >> /home/scripts/act/act.out fi cnt=0 sleep 5 done |