LinuxQuestions.org
Review your favorite Linux distribution.
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 03-24-2009, 08:34 PM   #1
iggymac
Member
 
Registered: Aug 2001
Posts: 77

Rep: Reputation: 15
Piping expect output to bash shell?


I have a bash script that ssh's into a server, twice, like so:

ssh user@server 'ls /dir1/' > /tmp/file_listing

to get a directory listing (which I then pass to "select")

and

ssh user@server ’cat /dir1/backupX.img.gz’ | gunzip -c | ntfsclone --restore-image --overwrite /dev/hda1 -

to, obviously, write an ntfsclone image to a partition.


I would like this script to only ask for the ssh password once, then pass it to both ssh commands, and the only way I can find to do this is with "expect".

But the problem is that both ssh commands need to return data to the shell. The first redirects the ls listing to a temp file, and the second pipes the output to gunzip and ntfsclone.

Is this possible?

Bret
 
Old 03-25-2009, 03:20 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
While you could put the password in you're violating the benefit of ssh by having to store your password in clear text. Why not instead set up an ssh trust so that when ssh logs in it doesn't ask for the password at all?
 
Old 03-26-2009, 11:25 AM   #3
iggymac
Member
 
Registered: Aug 2001
Posts: 77

Original Poster
Rep: Reputation: 15
I had thought of that, but I'm making a custom linux cd, and thought that might be dangerous - having a cd that has the key to the image server.

But I think I may just do that, because of the plain text password issue, and because I can't figure out how to do it anyway.

Thanks!

Bret
 
Old 03-26-2009, 12:48 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
No problem.

The CD bit is new information.

I'd thought you were just doing a machine to machine setup. If you're trying to propagate this out to multiple insecure locations you probably want to have a jail area on your main system for each of the remove locations (that is don't use the same user for every one of them). That would allow them to dump the file to the jail area. You'd then put a process in place on your main system that copied the information out of the jail into an area none of the CD based systems could reach.

Better yet might be doing an ssh FROM the main system to the CD based systems so the security is controlled by the main system and you don't have to worry about compromise of the remotes except as it affects their invidual data.
 
Old 03-26-2009, 02:53 PM   #5
iggymac
Member
 
Registered: Aug 2001
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks for the advice. I'm not too familiar with chroot jails (if that's what you're talking about), so for now, I guess I'll stick to my inelegant-put-your-ssh-password-in-twice setup.

But thanks again!

Bret
 
Old 03-27-2009, 03:34 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
You can use connection multiplexing to make ssh ask for the password only once:
Code:
ssh -fNM -o "ControlPath $HOME/%r@%h:%p.ssh" user@server

ssh -o "ControlPath $HOME/%r@%h:%p.ssh" user@server echo one
ssh -o "ControlPath $HOME/%r@%h:%p.ssh" user@server echo two

ssh -o "ControlPath $HOME/%r@%h:%p.ssh" -O exit user@server
If you put ControlPath /home/user/%r@%h:%p.ssh in /home/user/.ssh/config you don't need to put it in all the commands.
 
  


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
Help on my Linux Homework ! bash shell script / input-output data etc Bebelindo Programming 2 03-03-2009 12:51 PM
Piping output fm cut into sed wtaicken Programming 7 12-09-2008 10:54 AM
piping output of find to vim babu198649 Linux - Newbie 4 07-24-2008 06:25 AM
Piping output between processes. C. banan Programming 1 11-12-2006 11:25 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 03:40 AM

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

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