LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-02-2009, 10:44 AM   #1
ihickman
LQ Newbie
 
Registered: Feb 2008
Posts: 6

Rep: Reputation: 0
ssh shell script question


Hello;

Background:

I am using a software building management tool (Quickbuild), that after a successful nightly build, calls a bash shell script to scp the nightly artifact to a deployment server, then ssh logs in, extracts the artifact, then executes a smoke test, however I am receiving false positives due to the bash shell script that it calls.

Problem:

Even though I have configured public-key authentication on ssh, sometimes it prompts me for a password. What I would like to include in my script, is the ability to recognize that a password prompt is displayed an then 'exit 2' if it does.

Shell script:

#!/bin/sh
#
#
# Copy build artifacts to remote system
cd $artifactsDir
files=`ls`
for file in $files; do
scp $file user@hostname:/opt/prod/smoketest/dropbox
done

Nutshell:

How do I add the ability to check if a password prompt is displayed when performing ssh/scp? I want the script to abruptly end if a prompt is displayed, so that the building management software shows "build failed".
 
Old 02-02-2009, 10:58 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by ihickman View Post
Even though I have configured public-key authentication on ssh, sometimes it prompts me for a password. What I would like to include in my script, is the ability to recognize that a password prompt is displayed an then 'exit 2' if it does.
You're looking for a workaround, not for a solution to the real problem. Why should it ask for password if Private/Public Key authentication is in action?

You can start by forcing the Public Key Authentication using the following option:
Code:
scp -o PasswordAuthentication=no $file user@hostname:/opt/prod/smoketest/dropbox
this forces the scp command to never attempt password authentication. In this way you can check the exit status of the scp command, that will be 1 if the copying has failed, 0 if the copy was successful.

You may also consider the -i option of ssh/scp to specify the name of the private key to use for the negotiation.
 
Old 02-02-2009, 11:03 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
One option is to use expect. However, you shouldn't be seeing a prompt for a password when you log in.

Check if you have made the settings on the server that are suggested in the /etc/ssh/sshd_config file above the "UsePAM" line.

Code:
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
If these are enabled, they may be tried.

Using ssh-agent & ssh-add you can protect your private key with a passphrase but not be prompted for it after entering it using ssh-add. However this only works for the current shell, so you want ssh-add run by your ~/.profile script when you log in or start Quickbuild from the shell (or a subshell) from where you ran ssh-add.
 
Old 02-02-2009, 11:09 AM   #4
selboo
LQ Newbie
 
Registered: Dec 2007
Posts: 1

Rep: Reputation: 0
????????????????
 
Old 02-02-2009, 01:10 PM   #5
ihickman
LQ Newbie
 
Registered: Feb 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks

Thank you for the suggestions. I was able to catch the error response from the ssh command at the beginning of the script:

ssh user@hostname 'ls'
if [ $? == 255 ]; then
echo "ERROR with SCP/SSH -- Exiting"
exit 2
fi

I know its ugly, but I need QuickBuild to recognize if their are any problems with SSH/SCP, and if the above command does not execute properly, then I need QuickBuild to stop, as with the suggestions concerning the -o -i input, failure to connect still only shows as a warning in the logs, and succeeds the build without properly deploying and running the smoketest.

Last edited by ihickman; 02-02-2009 at 01:13 PM.
 
  


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
cgi shell script: ssh not working kitmui Programming 2 04-21-2010 02:46 PM
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
how to ssh in two machine one after another (in sequence) using shell script kushkothari Linux - Networking 21 10-21-2008 10:03 PM
Ssh or logging from shell script Alek Linux - General 5 09-24-2003 10:30 AM


All times are GMT -5. The time now is 01:14 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