Knowledgebase


Portal Home > Knowledgebase > Dedicated Server > How to set up a logging script?


How to set up a logging script?




Setting up an automatic logging script and reviewing its results can save your Dedicated server from constant memory problems and unreasoned CPU usage spikes.   

The given below sh script can be run every minute through cron to let you track considerable data within minutes that might be causing server crash/freeze.  

Data gets saved in logging directory using the number for the minute as file name. In the script setup below, 60 files are created which get refreshed with new data every hour:

  • #!/bin/sh
  • TERM=vt100
  • export TERM
  • time=$(date)
  • min=${time:14:2}
  • top -b -n 1 > /home/my-home/log/$min
  • ps aux >> /home/my-home/log/$min
  • exit 0

It must be noted that running above script without any knowledge of logrotate can load up your server’s disk space in less than a second. The best solution is to set the script to save data to /tmp so that if this partition gets overfilled, it get cleaned up easily.

 


Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read

Language: