LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-13-2006, 08:04 PM   #1
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Distribution: Frustrated Ubuntu 6.10 Edgy User
Posts: 257

Rep: Reputation: 30
Idiotically simple bash script problem.


Hi,
I'm using a dynamic IP address on one of my machines, but I need SSH access to it so I registered for a dynamic DNS name with dyndns.org.

I was looking through the unofficial ubuntu guide, and they suggest that in order to keep upto date with the DNS records, to write a simple script to update the server.

The script is as follows:

Code:
USERNAME=myusername
PASSWORD=mypassword
HOSTNAME=myhostname.getmyip.org

cd /root/

if [ -f /root/ipcheck.dat ]; then
  ipcheck.py -l -v -r checkip.dyndns.org:8245 $USERNAME $PASSWORD $HOSTNAME
else
  ipcheck.py --makedat -l -v -r checkip.dyndns.org:8245 $USERNAME $PASSWORD $HOSTNAME
fi
I know that the first line doesn't say #!/bin/bash, their script doesn't include it, so I haven't included it either, although I've tried it and it didn't make a difference because I'm calling sh anyway. DynDNS have over 40 TLD's and getmyip.org is one of them. The problem is, I get this when run as root in /root (with all correct permissions):

Code:
me@mymachine:/root$ sudo sh dyndns_update.sh
Password:
: command not foundine 4:
: command not foundine 6:
dyndns_update.sh: line 11: syntax error near unexpected token `fi'
dyndns_update.sh: line 11: `fi'
me@mymachine:/root$
and debugging mode gives:

Code:
me@mymachine:/root$ sudo sh -x dyndns_update.sh
+ USERNAME=$'myusername\r'
+ PASSWORD=$'mypassword\r'
+ HOSTNAME=$'myhostname.getmyip.org\r'
+ $'\r'
: command not foundine 4:
+ cd /root/
+ $'\r'
: command not foundine 6:
dyndns_update.sh: line 11: syntax error near unexpected token `fi'
dyndns_update.sh: line 11: `fi'
me@mymachine:/root$

Could someone please help me? I'm not great with bash but I do know some basic scripting such as what is in my sig, and I've tried allsorts with this but to no avail. I know that the ipcheck.py commands work, and I get the exact same result if I echo these lines.

Many Thanks in advance,

Last edited by morrolan; 01-13-2006 at 08:08 PM.
 
Old 01-13-2006, 08:58 PM   #2
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
Quote:
Originally Posted by morrolan
Hi,
if [ -f /root/ipcheck.dat ]; then
change this to

if [ -f /root/ipcheck.dat ]
then





no ; since it means new command and breaks the
fi at the end
 
Old 01-14-2006, 05:39 AM   #3
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Distribution: Frustrated Ubuntu 6.10 Edgy User
Posts: 257

Original Poster
Rep: Reputation: 30
I've already tried that, and just tried it again, with no difference.

I thought that a semi-colon was just a replacement for a new-line character, allowing you to maximise space and make more sense, by allowing you to execute the commands before the ; and then after. As BASH reads one line at a time and then executes what it found in the line - it doesn't go through executing each command as it finds it.
 
Old 01-14-2006, 07:15 AM   #4
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
It looks as if your script contains CR characters. Get rid of them, eg:

strings oldscript >newscript
 
Old 01-14-2006, 08:00 AM   #5
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
Quote:
Originally Posted by morrolan
I've already tried that, and just tried it again, with no difference.

I thought that a semi-colon was just a replacement for a new-line character, allowing you to maximise space and make more sense, by allowing you to execute the commands before the ; and then after. As BASH reads one line at a time and then executes what it found in the line - it doesn't go through executing each command as it finds it.
if ls $HOME/fridge/*beer 1>/dev/null 2>&1
then
echo "You have beer! The fridge contains the following:"
for i in $HOME/fridge/*beer
do
head -n 1 $i
done
else
echo "You have no beer! I'll get some."
fi

this seems to work on mine :S
 
Old 01-14-2006, 04:22 PM   #6
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Distribution: Frustrated Ubuntu 6.10 Edgy User
Posts: 257

Original Poster
Rep: Reputation: 30
carl0ski, that isn't what I'm having a problem with, that's my signature!

 
Old 01-14-2006, 04:46 PM   #7
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
I think it can't find ipcheck.py - can you put the full path to those python scripts in and see what happens.
 
Old 01-14-2006, 05:09 PM   #8
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Distribution: Frustrated Ubuntu 6.10 Edgy User
Posts: 257

Original Poster
Rep: Reputation: 30
Hi guys, problem solved - in case anyone is interested, there is nothing wrong with the script itself.

I moved it into /home/me/dyndns/ and changed the script accordingly, and now it seems to work fine!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple bash script Soulful93 Programming 1 06-04-2005 07:26 PM
Simple Bash Script dmedici Programming 9 12-31-2004 03:48 AM
Help with simple bash script - please tw001_tw Linux - Software 5 12-19-2004 09:02 PM
problem with a simple script bash stockerz Linux - Newbie 1 09-21-2004 11:42 AM
Simple BASH script fio Linux - General 5 01-18-2003 03:26 PM


All times are GMT -5. The time now is 09:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration