Now this was one scenario I was into, there can be others where you need to monitor an event on a per second wise so what should we do?
Here is what I did.
Created a cron job entry for every second
To edit the cronjobs use the below command
# crontab -e
* * * * * while true; do df -h /tmp >> /root/filesystem.txt & sleep 1; done
Save and exit
Here the output of df -h /tmp will be stored inside /root/filesystem.txt every second.
Now lets monitor the output. For live feed and changes inside any file use the below command
# tail -f /root/filesystem.txt
6.8G 4.3G 2.2G 66% /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-root
6.8G 4.3G 2.2G 66% /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-root
6.8G 4.3G 2.2G 66% /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-root
6.8G 4.3G 2.2G 66% /
So, as you see the above command started showing me live output, using which I was able to identify the time of the spike and the rest of the story is not relevant to this article.
But the bottom line is you can use the above script to run any of your cron jobs for every second.
The same if you want to change for 5 second, just adjust the sleep value as per your requirement.
Another example
# crontab -e
* * * * * while true; do date >> /root/date.txt & sleep 1; done
# tail -f /root/date.txt
Thu Jun 19 11:12:24 IST 2014
Thu Jun 19 11:12:25 IST 2014
Thu Jun 19 11:12:26 IST 2014
Thu Jun 19 11:12:27 IST 2014
Thu Jun 19 11:12:28 IST 2014
Thu Jun 19 11:12:29 IST 2014
Thu Jun 19 11:12:30 IST 2014
Thu Jun 19 11:12:31 IST 2014
Thu Jun 19 11:12:32 IST 2014
I hope I made my self clear
Related Articles:
How to track all the successful and failed login attempts by users in Linux
How to check last login time for users in Linux
How to create user without useradd command in Linux
How to give permission to user to run some commands in Linux