LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 09-12-2006, 05:02 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
bash script error


I have got a script which will decrypt a GPG encrypted password file and logs me in to the server automatically using ssh key. But it's giving an error since I added a server "venus" which is an exception to the generic rules.

Code:
1 if [ -f $DECRYPT ]; then
2    if [ $1 = "venus" ]; then
3        ssh -p 23000 me@venus
4    fi
5 else
6 grep -i $1 passwd.txt
7 ssh -i ssh_key admin@$1
8 else
9   echo "no decrypted passwd file found"
10   gpg -d passwd.txt.gpg > passwd.txt
11   grep -i $1 passwd.txt
12   ssh -i ssh_key admin@$1
13 fi
here's the error I get when I run the script - ./password.sh venus

Code:
syntax error near unexpected token `else'
line 8 `else'

Last edited by noir911; 09-12-2006 at 05:05 AM.
 
Old 09-12-2006, 05:13 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
You have two else statements for one if. (Lines 5 & 8) Should one of them be an elif?
 
Old 09-12-2006, 05:41 AM   #3
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Thanks for your reply. I have just substituted the else in line 5 with elif and also the else in line 8 with elif. But still getting the same error.
 
Old 09-12-2006, 06:00 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

elif should be followed by an expression:

if [ something ]
then
....
elif [ something else ]
....
else
....
fi


Hope this helps.
 
Old 09-12-2006, 06:10 AM   #5
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Things were clearly not matched up right. Substituting elif for both elses would clearly not be right either, as well as elif requires a condition to test.

I haven't really figured out what you are trying to do, but making another wild stab at it, is the following what you were trying to do?

Code:
if [ -f $DECRYPT ]; then
   if [ $1 = "venus" ]; then
       ssh -p 23000 me@venus
   else
       grep -i $1 passwd.txt
       ssh -i ssh_key admin@$1
   fi
else
   echo "no decrypted passwd file found"
   gpg -d passwd.txt.gpg > passwd.txt
   grep -i $1 passwd.txt
   ssh -i ssh_key admin@$1
fi
 
Old 09-12-2006, 06:42 AM   #6
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Thanks guys. I have solved the problem. Here's what the solution looks like -

Code:
1 if [ -f $DECRYPT ]; then
2   if [ $1 = "venus" ]; then
3      ssh -p 23000 me@venus
4   fi
5 grep -i $1 passwd.txt
6 ssh -i ssh_key admin@$1
7
8 if [ ! -f $DECRYPT ]; then
9   echo "no decrypted passwd file found"
10   gpg -d passwd.txt.gpg > passwd.txt
11   if [ $1 = "venus" ]; then
12      ssh -p 23000 me@venus
13   fi
14   grep -i $1 passwd.txt
15   ssh -i ssh_key admin@$1
16 fi
I have a plan to put line 2-4 and 11-13 in a function somewhere.
 
  


Reply



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
Do not show ls error in bash script Rindert Linux - General 2 08-18-2006 05:28 PM
bash script error noir911 Programming 4 07-25-2006 03:58 AM
error when tying to run python script(bash error?) shanenin Programming 5 01-10-2006 10:01 AM
bash script error near 'else' ? nutthick Linux - Newbie 5 01-23-2005 03:41 PM
bash script error corbis_demon Linux - Newbie 7 09-27-2004 10:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:23 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration