Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-25-2003, 02:26 PM   #1
Registered: Oct 2003
Location: ITALY
Distribution: Debian, Ubuntu, Fedora
Posts: 137

Rep: Reputation: 15
Bash scripting... ssh?

Hi all,
I'm very new to bash scripting and I am a bit confused about a few things.
My question is:
is there a way to pass commands to an interactive program?
An example could be ssh, how do I make a script that commits an ssh connection, gives the password and input some commands to a remote box?
I know this is a quite newbie question but, hey, I'm doing my best!
Thank you all!
Old 11-25-2003, 03:11 PM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
As an example:

Let's say a file called myscript contains a series of commands:

open myhost
cd /somewhere
get somefile

You can then pass these commands to ftp (or any other program. I created a simple ftp script as an example):

 ftp < myscript
Old 11-25-2003, 03:38 PM   #3
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Another nice tool for that kind of thing
is expect.
Old 11-25-2003, 05:58 PM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
As for the ssh example, you can use RSA authentication so you don;t need to enter a password, and then start ssh (from a script) more or less like this:
ssh -l username " script command #1
script command #2
script command #3
script command #4"
cat somescipt  | ssh -l username -
I didn't actually try this, but it should be possible, or at least quite similar.
Old 11-27-2003, 09:37 AM   #5
Registered: Oct 2003
Location: ITALY
Distribution: Debian, Ubuntu, Fedora
Posts: 137

Original Poster
Rep: Reputation: 15
well, for authentication I'll try another way.
Thank you all


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
Bash scripting vinoth.ilango Solaris / OpenSolaris 6 10-29-2004 05:41 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 05:09 AM
Bash, SSH and scripting. Namuna Linux - Newbie 2 06-08-2004 03:01 PM
bash scripting -=MaGo=- Programming 16 08-30-2003 08:07 PM
BASH scripting help Chucklez Linux - Newbie 4 12-12-2002 01:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:06 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration