There are several ways to do performance control. In past blogs, I already mentioned different ways to see your server’s performance and how to tune it. In this blog, we focus on automatically control of the performance.
As we know, the more transactions come, the more pressure the server undertakes. In this case, we need an automatical way to know the server’s status. Here we introduce two ways, one is crontab, one is loop.
- several important commands which we need to know.
// edit crontab script crontab -e // list active crontabs crontab -l // view log file to check crontab's status sudo grep cron /var/log/syslog
- Step1: you need to write a script, for example its name is autocheck.sh.
nohup sh -c `while true; do <your_script>.sh >> <your_log>.txt; sleep 1800; done` &
Here 1800’s unit is seconds, so it is equal to 30 minutes.
Please note, here <your_script>.sh is the real content which you want to do, not autocheck.sh.
In this line, we use three important commands:
It makes your job keep running in the background when the process gets sighup.
It essentially returns control to you immediately and allows the command to complete in the background.
- while … do … done
- sleep 1800
- Step2: run this script.
- Step3: check your log, you will see what you want to print out.