LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-29-2012, 11:36 AM   #1
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 15

Rep: Reputation: Disabled
getting return code from command with piped input


I have the following line in a bash script:
echo password > ssh root@domain command
I want to get the status (return code) from the SSH command, NOT the ECHO command. The SSH connects (it gives me a "success" message). The command is not working for some reason and I want to determine the reason. I have several commands, (each on a separate SSH line in the script) and want to be sure they all work, before concatenating them into one <compound-command> in a single script line.

I own multiple (about 35) Linux machines and need to manage them remotely. They all have the same id (root) & password for management. I am building an .ssh directory with my pubkey in the auhorized_list to do this more effectively in the future.
 
Old 09-29-2012, 11:46 AM   #2
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

Rep: Reputation: 186Reputation: 186
I think your command line is wrong, namely the ">" is used to write to a file, not to pipe commands together.
Try switching to "|" (pipe).
The password you're echoing is for the ssh authentication on the remote host?
 
Old 09-30-2012, 01:21 PM   #3
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
I tried switching to "|" and that while it appeared to make the ssh connection, the comand following it was not recognized. The command is "mkdir" with all the necessary parameters.

Yes, I am passing the password via echo (hence the >), to ssh, so I don't have to keep retyping it. I have been told that doing:
echo "something" > pgm
will act as if I were typing it from stdin.

Last edited by noguru; 09-30-2012 at 01:31 PM.
 
Old 09-30-2012, 01:38 PM   #4
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

Rep: Reputation: 186Reputation: 186
Let me tell you that you're doing it wrong
Instead of using a password login with ssh switch to a password-less authentication.
There are tons of tutorials on how to do it on the web. This is just one of the many out there.
 
Old 09-30-2012, 02:31 PM   #5
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by 414N View Post
Let me tell you that you're doing it wrong
Instead of using a password login with ssh switch to a password-less authentication.
There are tons of tutorials on how to do it on the web. This is just one of the many out there.
Thanks for the RSA advice, but it does not answer my question OR solve my problem. As I mentioned originally, I own about 35 PC's on a private network. They currently have no .ssh directory and thus no RSA keys installed. What I want to do is programmatically install MY public key on those PC's, THEN I can use the normal RSA-key mechanism. In the FUTURE of these PC's, their O/S images will include my key in an .ssh directory. I do NOT have the luxury of rebuilding them now (and won't until January) and I do not have time to login to each machine and type commands to install the keys.

And yes, if I had KNOWN I would need to do this remote access, I would have installed the keys before I put the machines to use.
 
Old 09-30-2012, 03:29 PM   #6
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
for that to work I believe you have to write the script with expect

Quote:
#!/usr/bin/expect

spawn ssh root@server
expect "password"
send Fdefg43GFSe
spawn Mkdir etc
Interact
 
Old 10-01-2012, 07:57 AM   #7
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cbtshare View Post
for that to work I believe you have to write the script with expect
I've installed "expect" and started looking for usage examples that might help me ocnvert my bash script (with a for..in loop) toan "expect" script. I need to loop through 35 of these ssh comands with substitutions of the ssh host. Can you point me to some examples that are more than simple while {1} loops and allow substitutions and string concatenation with variables (ie. the usual bash scripting actions)?
 
  


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
[SOLVED] Problem using piped data as input NirvanaII Programming 13 11-07-2010 08:03 AM
Automatically append another piped command to issued command in bash amateen Programming 1 05-07-2009 07:36 AM
Single Command To Close Window and Return Exit Code jagooch Programming 3 01-02-2009 04:33 AM
Using piped input in a BASH script gnashley Programming 1 08-05-2007 11:50 AM


All times are GMT -5. The time now is 08:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration