Some user abusing your cron jobs and you don’t know who the owner is?
I have a simple script to scan users cron jobs and email you the report.
Required: root access
Let start…
[*] Login to your server via SSH
[*] Type:
cd /root
[*] Type:
pico scanCron.sh
If pico doesn’t work for you, try:
nano scanCron.sh
[*] Copy paste the following:
#!/bin/sh
emailAddress=$1
if [ -n "$emailAddress" ] ; then
mycrontmp=/root/scanCron.tmp.$$
for i in `cat /etc/passwd | cut -f1 -d ':' | grep -v '#'`; do
echo "--------------------------------------------------"
echo "Username: ${i}"
echo "--------------------------------------------------"
crontab -u ${i} -l 2>&1
echo "--------------------------------------------------"
done > $mycrontmp
cat $mycrontmp | mail -s "Cron jobs report for `hostname`" ${emailAddress}
rm -f $mycrontmp
else
echo "Please supply a valid email address."
exit
fi
[*] Press “Ctrl” + “O” to save.
[*] Type:
chmod +x scanCron.sh
To run it, just type:
./scanCron.sh emailAddress@domain.com
You can automate this by adding it to cron job. Below is how:
[*] Type:
crontab -e
[*] Insert the following after the last line:
10 1 * * * /root/scanCron.sh emailAddress@domain.com
This will run everyday at 1:10am.
This can be applied to cPanel server.
Good luck!