Saturday, May 22, 2010

Using Cron and Dropbox to monitor a server

I've been dealing with a server that has an issue, and I keep trying to get things to work right.  I thought it might be nice to know (without having to check and potentially without being at home) if the server is operating correctly by copying the runtime file (which tells how long the server was running).

So, the first thing I've done was open a Dropbox account and install Dropbox CLI.  This, by default, sets the folder to ~/Dropbox on Linux.

Then, I created a cron job to copy the runtime file every five minutes:
$crontab -e

In vim, which is the default editor in CentOS (and probably many others), you'll need to press 'i' to get into insert mode.  Use the following in the crontab file:
5,10,15,20,25,30,35,40,45,50,55,0     *     *     *     *     cp -f /proc/uptime ~/Dropbox >/dev/null 2>&1

Then, in vim, press esc, ':', and 'wq' and press enter.

Now, every 5 minutes the runtime file will be copied to the Dropbox folder and synced to Dropbox.  Even better, this can be extended to include reports (perhaps those generated by Nagios or another monitor program).

No comments:

Post a Comment