Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab command fails but .sh file appears to run 2

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
0
0
GB
Hi all

Have reinstalled Ubuntu Server 11.04 and have the following crontab command
Code:
MAILTO me@mydomain.com
*/5 * * * * /var/data/bin/zoneedit.sh
The file /var/data/bin/zoneedit.sh appears to run in the command window.

The content of zoneedit.sh is
Code:
#!/bin/bash

ipfile='/var/data/bin/ipaddress'

[[ -f "$ipfile" ]] && ipold="$(< "$ipfile" )"

ipnew="$( wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //;s/<.*$//' )"

if [[ "$ipold" != "$ipnew" ]]; then

  echo "$ipnew" > "$ipfile"

  /usr/sbin/ssmtp me@mydomain.com < /var/[URL unfurl="true"]www/ipaddress[/URL] 

  wget -O - --http-user=Me --http-passwd=Password '[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=www.mydomain.com'[/URL]

  wget -O - --http-user=Me --http-passwd=Password '[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=mydomain.com'[/URL]

fi
As far as I know, the code is exactly as was before reinstalling. The file /var/data/bin/ipaddress exists and even if IP address in the file is the current external IP address it still fails, so the error is not in the second half of the program.

The ownership of the folder/files etc is mine.

The error message emailed is
Code:
/bin/sh: /var/data/bin/zoneedit.sh: not found

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Just to clarify, the following code with correct details from the second half of the .sh file executes as expected.
Code:
wget -O - --http-user=Me --http-passwd=Password '[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=www.mydomain.com'[/URL]

wget -O - --http-user=Me --http-passwd=Password '[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=mydomain.com'[/URL]


FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
...and if you try to run
Code:
/var/data/bin/zoneedit.sh
from the terminal, the error is
Code:
bash: /var/data/bin/zoneedit.sh: //bin/bash^M: bad interpreter: No such file or directory
The earlier comments concerning running the file related to directly executing the file in the folder /var/data/bin/

HTH

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Hi

Chris said:
bash: /var/data/bin/zoneedit.sh: //bin/bash^M: bad interpreter: No such file or directory
Now that says it all : the script was copied over to a Windows machine and the file got DOS end-of-line marks.

So clean it up with :
Code:
dos2unix /var/data/bin/zoneedit.sh

[gray]# or[/gray]

sed -i 's/\r$//' /var/data/bin/zoneedit.sh
Or just run it as :
Code:
bash /var/data/bin/zoneedit.sh


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top