As a sysadmin, we strongly discourage things like this when other people do them. This is a terrible script. You shouldn't be running this script. But sometimes you need to do terrible things and run terrible scripts like this. So here it is:
#!/bin/bash FREE_MEMORY=$(free -m | grep Mem | cut -d' ' -f 28) THRESHOLD=150 LOG=low-memory-fixer.log APACHE_STATUS=$(service httpd status) if [ "$FREE_MEMORY" -lt "$THRESHOLD" ] then echo -e "Time to reload Apache. Current memory value is $FREE_MEMORY, lower than the current threshold of $THRESHOLD. Reloading Apache. Date is $(date)." >> $LOG service httpd reload echo -e "Apache status is $APACHE_STATUS. Date is $(date)." >> $LOG else echo -e "Memory is still good. Current memory value is $FREE_MEMORY, higher than the current threshold of $THRESHOLD. Nothing to do here! Date is $(date)." >> $LOG fi |
You'll want to create the log file in the same directory the script is running in - "touch low-memory-fixer.log" is sufficient. If you want to set up a cronjob that runs this script every 10 minutes, run "crontab -e" as the user this being run by and add a line like this: "*/10 * * * * bash /path/to/the/script/goes/here/low-memory-fixer.sh".
This script was written in five minutes. This script is one of the worst solutions I've seen in my professional career. Don't run this script. All humor aside, if you're running this script, you really need to dig into Apache and find out what's going on, or to get someone who can do that to look at your server.
No comments:
Post a Comment