I have an sh file called m.sh
with the contents:
echo "Cleaning memory"
sync; echo 3 > /proc/sys/vm/drop_caches
echo ""
free -m
echo ""
ps cax | grep java > /dev/null
if [ $? -eq 0 ]; then
echo "== Server is already running =="
else
sh a.sh
echo "========== STARTING THE SERVER =========="
fi
When I run it with sh m.sh
it works perfectly. But I need it to run every 5 minutes, so I am using cron jobs. It needs to work as root/sudo so I did sudo -s
, then crontab -e
and wrote this in the file:
0,4,9,14,19,24,29,34,39,44,49,54 * * * * /bin/sh /home/<username>/m.sh
I had done some research, and I learned that the cron has different paths than the user, that is why I used those absolute paths, to make sure.
The cron job wasn't running the script every 5 minutes, as it was supposed to.
I also added
* * * * * /bin/echo "Testing123"
to test if cron was working at all, and nothing came up in the console.
How can I make the cron run the script every 5 minutes? I did research online, and tried the solutions, but couldn't make it to work for me. I did service cron start
and it said it was already running. I also restarted the service. The permissions are set correctly, I gave all users read, write, and execute permissions just to make sure (I know the permissions are correct).