CRON task in Linux

I cannot get a cron task to run in linux on a Rpi.

I’m logged in as user ‘pi’ and used the command
crontab -e
to create the file

*/1 * * * * /home/pi/cron_scripts/nettask

To run once per minute

Then, I created a file in /home/pi/cron_scripts called nettask

I made the file executable with ‘sudo chmod +x nettask’

nettask is a file with the contents:

#!/bin/bash
ping -c 1 -q 8.8.8.8
if [ “$?” -eq 0 1 ]; then
printf “%s\n” “SUCCESS”
else
printf “%s\n” “FAIL”
fi
exit 0

But it does not run. Why?
I will eventually replace the text messages (SUCCESS/FAIL) with a Python script to drive a GPIO pin high or low to turn a LED on or off depending on whether or not there is a network connection.

Make sure your time is set correctly (and ntpd is running). The raspberry pi doesn’t have a battery backed clock, so it doesn’t know the time until ntpd sets it.

If crontab -e works, I’ll assume cron is up and running too. Try a simpler task, like echoing hello or touching a specific file or logging a message to make sure cron is executing your program. I assume cron should run with root privileges, but just in case, make sure that your cron user has read and execute permissions on your script and it’s ancestor directories.

You could also look in the system logs and see if cron is logging any errors. You could also configure an email server to mail you the cron output upon running your script.