LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-07-2006, 05:27 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
bash script problem


I am writing a small bash script which tries to connect the user to a server (server name is taken as a command line argument - $1) using SSH key.

It is supposed to try the first key & upon failure it should try the next one. But it exits if it cannot connect using the first key. The code looks something like this -

ssh -i key1 user@$1 || ssh -i key2 user@$1
 
Old 04-07-2006, 09:04 AM   #2
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 417

Rep: Reputation: 53
You may want to try something more along the lines of this:

Quote:
#!/bin/bash
TEST=`ssh -i key1 user@$1`
if [ ! TEST ]; then
ssh -i key2 user@$1
fi
I am just coming up with this out of my head, and no testing is involved at all.

Something you may also want to think about, since it appears that what you are trying to do is authenticate using two different keys, so that if the location you are going to doesn't have the first key it tries the second key, is to simply import the first key into the location that doesn't have it.
 
Old 04-07-2006, 10:11 AM   #3
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
You can try something like, ssh -i key1 -i key2 user@$1, though I am not sure it will have the desired result. I'm guessing, even if the key is wrong, it's not returning w/ an error code, so the other half of the || doesn't execute. Run the first one where it will not go through, then type: echo $? -- that will show you the return value of ssh, if it's 0, your going to have to find some other way to see if it failed.
 
  


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
Problem with bash script. cheater1034 Programming 9 11-21-2005 10:29 PM
bash script problem fatbastard spice Linux - General 2 08-24-2005 02:15 AM
bash script problem GATTACA Programming 3 06-13-2005 09:59 AM
Problem with this bash script cantabile Programming 3 06-06-2005 05:31 PM
Problem with bash script cowardnewbie Programming 1 10-01-2001 06:53 AM

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

All times are GMT -5. The time now is 05:32 PM.

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