I'm using a basic shell script to log the results of top, netstat, ps and free every minute.
This is the script:
/scripts/logtop:
TERM=vt100
export TERM
time=$(date)
min=${time:14:2}
top -b -n 1 > /var/log/systemCheckLogs/$min
netstat -an >> /var/log/systemCheckLogs/$min
ps aux >> /var/log/systemCheckLogs/$min
free >> /var/log/systemCheckLogs/$min
echo "Message Content: $min" | mail -s "Ran System Check script" [email protected]
exit 0
When I run this script directly it works fine. It creates the files and puts them in /var/log/systemCheckLogs/ and then sends me an email.
I can't, however, get it to work when trying to get cron to do it every minute.
I tried putting it in /var/spool/cron/root like so: * * * * * /scripts/logtop > /dev/null 2>&1 and it never executes
I also tried putting it in /var/spool/cron/myservername and also like so: * * * * * /scripts/logtop > /dev/null 2>&1 it'll run every minute, but nothing gets created in systemCheckLogs.
Is there a reason it works when I run it but not when cron runs it?
Also, here's what the permissions look like: -rwxrwxrwx 1 root root 326 Jul 21 01:53 logtop drwxr-xr-x 2 root root 4096 Jul 21 01:51 systemCheckLogs