1

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
2

Replace

> ip.address.txt

with

> /home/jj/Desktop/IP/ip.address.txt
  • wow. I can't believe I missed that. I read about how the paths have to be completely written out and yet I still missed one. LOL I feel dumb. Thanks. And thanks for the editing tips. – user230285 Feb 1 '16 at 6:17
  • Thats what variables are for ^^ – s1mmel Nov 30 '17 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.