I am not quite sure what I am doing wrong. I am trying to create a cron job to run a bash script. The bash script will basically check my file (ip.address.txt
), find my public ip address, then check ip.address.txt
again and compare the two. If they are different, my IP has changed and I should get a notification via email.
The script works manually, however, when attempting to add to a cron job, I then get an email saying that Delivery to the following recipient failed permanently
. I am running Ubuntu 14.04.3. I am attempting to do my first cron job using the command crontab -e
". At the end of the file (everything about has been commented out), I have :
PATH=/usr/sbin:/usr/bin:/sbin:/bin
* * * * * /home/jj/Desktop/IP/publicIP.sh
This is a standalone desktop, and trying to do a user cron job. Thank you for your help on understanding more on cron jobs. I will also post bash script.
#!/bin/bash
#Give crontab a path to follow according to what i have read ?????
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/jj/Desktop/IP/
#Get last saved IP address
ip1=$( cat /home/jj/Desktop/IP/ip.address.txt )
#This is the command to see public IP address
dig +short myip.opendns.com @resolver1.opendns.com > ip.address.txt
#This is the updated IP adress currently in use
ip2=$( cat /home/jj/Desktop/IP/ip.address.txt )
#Check to see if it is the same IP
if [ $ip1 != $ip2 ]; then
#If the IP is different, the IP has changed. Notify me via email
cat /home/jj/Desktop/IP/ip.address.txt | mail -s "IP Address" user@gmail.com
#EOF
fi