LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-01-2006, 07:52 PM   #1
anupamsr
Member
 
Registered: Sep 2004
Location: India
Distribution: Kubuntu, Archlinux, Suse, Gentoo, Mandrake
Posts: 371

Rep: Reputation: 30
Question Using SSH to start a program


Hi!

I want to write a script which will log into all the listed computers, run a list of commands, and then exit, then ssh to next computer and so on.

For this, I need to run the program after sshing and then exit the ssh environment.

How to do that?

The commands for the program is:
1. cd ~/1/
2. nohup /usr/bin/myprogram inputfile

then exit and then

1. cd ~/2/
2. nohup /usr/bin/myprogram inputfile

and so on...

How to do that?
 
Old 08-01-2006, 10:50 PM   #2
DrAxeman
Member
 
Registered: Jun 2004
Location: State of Confusion
Distribution: My other OS is your Solaris box.
Posts: 84

Rep: Reputation: 15
You can use the -C arguement and loop it something like:

for i in 1 2 3 4 5
do
ssh user@IP-Address -C "(cd ~/$i/ ; nohup /usr/bin/myprogram inputfile)"
done

Of course, to do this you'll need to setup ssh keys that allow you to login without a password.
 
Old 08-01-2006, 10:55 PM   #3
anupamsr
Member
 
Registered: Sep 2004
Location: India
Distribution: Kubuntu, Archlinux, Suse, Gentoo, Mandrake
Posts: 371

Original Poster
Rep: Reputation: 30
Thanks! I have already setup the ssh keys.
 
Old 08-02-2006, 01:48 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
On that note: one of ssh's lesser known features is the ability
to give a user the ability to only run ONE command on login by
adding the command to the authorized_keys file. Of course that
only makes sense for very specialised cases. But if you have a
tool that always needs to be run by an account that was specifically
created for that purpose it's a really tidy solution; you then
only need to do the loop and the ssh command. Or if you have the hosts
the keys are distributed to in a text file, one per line it gets as
simple as:
Code:
cat hosts|xargs -i ssh user@{}

Cheers,
Tink
 
  


Reply

Tags
bash, script, ssh



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I automatically start a program at start up? victordh Linux - General 7 10-27-2013 06:02 AM
Running Program Through SSH windisch Linux - General 6 10-04-2005 06:10 AM
SSH sessions locked to one program jav Linux - Software 2 11-17-2004 10:06 AM
I turned off SSH, but I cant get it back! How do you start SSH on boot? nmoog Slackware 2 02-08-2004 05:18 PM
Launching X Program from SSH deckmoney Linux - General 4 04-16-2003 04:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:05 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
Open Source Consulting | Domain Registration