I'm trying to execute my cron job with my user (user).
The cron job has no problem installing and the script works if I just execute it.
It is executable and I have the
bash flag to indicate it is a bash script.
I created the script by running
crontab -e logged in as
For testing purposes I will run this script every min but will eventually change it to 10 mins.
my cronjob should run my script which pings googles server every 10mins and creates a log of it so I can know if my devices ever loses internet connection to track an issue. I have another script that moves the log file every day and then logs it with a date and then this script should create another log file. currently it isn't making a file with this cronjob or updating the file once I run the script.
*/1 * * * * bash /home/user/ping_scripts/ping-test.sh
#!/bin/bash if [ "$(id -u)" != "0" ]; then exec sudo "$0" "$@" fi if [ ! -e /var/log/ping.log ];then touch /var/log/ping.log fi ping -q -c5 google.com > /dev/null if [ $? -eq 0 ];then echo -e "[$(date)] \t\t google ping successful" >> /var/log/ping.log else echo -e "[$(date)] \t\t google ping failed" >> /var/log/ping.log fi
I have read a few other solutions on, but non had fixed my error.
(I cant describe how my post is different other than it is simply a question, one that I could not find the answer to while going through Why crontab scripts are not working? which is for unique errors to cron and the solution wasn't really unique to cron specifically. it had more to do with my script. To get the answer please simply refer to the checked off answer below.)