LinuxQuestions.org
Review your favorite Linux distribution.
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 11-25-2003, 02:26 PM   #1
TheIrish
Member
 
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
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
As an example:

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

open myhost
cd /somewhere
ASC
get somefile
bye

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

Code:
 ftp < myscript
 
Old 11-25-2003, 03:38 PM   #3
LogicG8
Member
 
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.

http://expect.nist.gov/
 
Old 11-25-2003, 05:58 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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:
Code:
ssh -l username 10.0.0.122 " script command #1
script command #2
script command #3
script command #4"
or:
Code:
cat somescipt  | ssh -l username 10.0.0.122 -
I didn't actually try this, but it should be possible, or at least quite similar.
 
Old 11-27-2003, 09:37 AM   #5
TheIrish
Member
 
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
 
  


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
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


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