LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-04-2008, 10:22 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 419

Rep: Reputation: 31
bash - start remote script from local script?


i have a bash script that runs on my local computer
and moves files from one remote computer to another
for processing. the processing computer executes its
processing via its own bash script.

is there a way i can have my local computer's script
tell the processing computer to run its own processing
script? currently, i'm waiting for the local script to
complete and then going over to the processing computer
to start its script. would be a lot easier if i could
put it all into the local script. just have no idea
how.

thanks,
BabaG
 
Old 04-04-2008, 11:05 PM   #2
Neuzen
Member
 
Registered: Jun 2007
Distribution: Slackware, Gentoo, Debian
Posts: 36

Rep: Reputation: 16
using SSH

Hi babag,
My suggestion is to use ssh to send commands to your remote computer.
on your script you can add:

ssh <remote computer's IP address> <command>

I hope that I help a little bit.

B.T.W
You can even remove the request to enter password by adding your RSA key
to the remote computers authorized keys list.

Regards,
 
Old 04-05-2008, 11:50 AM   #3
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
great suggestion neuzen. one question: if, as you suggest,
i issue a command via ssh, and that command is to run a
script on the remote computer, when does my local script
continue? after the ssh command is issued? after the remote
script starts? after the remote script ends? if it's the
last of these possibilities i'd have a problem since the
remote script will take hours to run and i'm ready to move
on as soon as it's been told to start running.

thanks,
BabaG
 
Old 04-05-2008, 09:54 PM   #4
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
oops. just hit a snag. got ssh working and can start a remote
script from my local script (yay!). problem is, remote script
has to be in remote's home directory, not subdirectory. i
need to send both a cd command, as well as the command to
start the script. so far, all i know how to do is the login
and send one command. i have this to run the script if it's
in the home directory:

ssh useracct@remotecomputer ./script_to_run.sh

what i need to be able to do is something like:

ssh useracct@remotecomputer cd Documents/Scripts ./script_to_run.sh

how do i send more than just the one command?

thanks,
BabaG
 
Old 04-05-2008, 11:54 PM   #5
Neuzen
Member
 
Registered: Jun 2007
Distribution: Slackware, Gentoo, Debian
Posts: 36

Rep: Reputation: 16
no problem.

Hi BabaG,
This is no problem,
You just include the script path, for example lets say you want to run command from /sbin/MyCommand you should type:

ssh <remote computer IP> /sbin/MyCommand.

Or you can just include your command path to PATH (env. variable) on your remote computer.

Regards,
 
Old 04-06-2008, 12:00 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Including the full path to a command (or fully defining the environment) is best practice for scripts anyway. A change in the environment won't run the wrong command.
 
Old 04-06-2008, 12:35 AM   #7
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks neuzen and jschiwal. i had one of those 'DOH!' moments
driving home after posting the question when i realized just
what you're saying. i'd still be very interested, though, to
know about issuing multiple commands through an ssh script.

thanks again,
BabaG

Last edited by babag; 04-06-2008 at 12:37 AM.
 
Old 04-06-2008, 05:46 PM   #8
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
just noticed this:

ssh <remote computer IP> /sbin/MyCommand

has no "." before the command. running the command
without the path included i had:

ssh useracct@remotecomputer ./script_to_run.sh

is there no "."? or should it be:

ssh <remote computer IP> ./sbin/MyCommand

{EDIT}
ok. no "."
it works now.

thanks,
BabaG

Last edited by babag; 04-06-2008 at 06:19 PM.
 
  


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
Get script to start again at a certain point in the script (bash) helptonewbie Programming 11 01-11-2008 05:49 AM
clamd upgradation in remote mach through local mac by script to be run on local mach Narayandutt Programming 3 11-29-2006 10:00 AM
remote execute a bash script vmware Linux - Enterprise 3 09-07-2006 03:01 PM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 07:20 AM
using cron to start and stop a bash script monty Linux - Software 2 03-20-2006 02:30 PM

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

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