LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-12-2010, 03:04 PM   #1
jhameier
LQ Newbie
 
Registered: Mar 2010
Location: New Jersey
Distribution: CentOs5.4
Posts: 2

Rep: Reputation: 0
Running a bash script via ssh


New to Linux:

I have a hardware audit script I want to run on several remote machines around my office. Is there a way to run the script that resides on my machine via ssh or do I need to copy the script to the local machine and then run it...
 
Old 03-12-2010, 03:08 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
Probably copy it to each machine.
 
Old 03-12-2010, 03:45 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,336

Rep: Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895
Quote:
Originally Posted by jhameier View Post
New to Linux:

I have a hardware audit script I want to run on several remote machines around my office. Is there a way to run the script that resides on my machine via ssh or do I need to copy the script to the local machine and then run it...
Agree with smoker...you have to copy it to each machine. BUT, if each machine has access to a shared resource (like an NFS or Samba mount), you could run it like that.

Issuing a command like this:
Code:
ssh <user>@<remote box> "<mount command for NFS resource>;/path/to/script;<dismount command>"
would work. Of course, you'd still have to set up the shared resource, etc., so the work you save on copying the script would be offset by the work you'd do for the shared resource. If it's something you have to do often, setting up a shared resource would be a good thing. That way, you'd only have to change ONE script in one place, if you wanted to update it.
 
1 members found this post helpful.
Old 04-08-2010, 04:46 PM   #4
flyfishin
Member
 
Registered: Aug 2003
Location: KC, MO
Distribution: CentOS, RHEL, SuSE, Fedora
Posts: 243

Rep: Reputation: 30
It depends on how complicated the script is. If it's just a bash script, you could theoretically get it all on one line and ssh to each machine and have the script run. Here's an example:

ssh machinename "if [ -a /usr/bin/yum ]; then echo 'Updates via yum'; elif [ -a /usr/sbin/up2date ]; then echo 'Updates via up2date'; else echo 'Not RHEL';fi"
 
Old 04-09-2010, 07:35 AM   #5
jhameier
LQ Newbie
 
Registered: Mar 2010
Location: New Jersey
Distribution: CentOs5.4
Posts: 2

Original Poster
Rep: Reputation: 0
I'd have to agree with TBOne. Running it from a shared resource seems like the best course of action. At somepoint I will want to run the script automaticly but for now I will install the script in a shared directory. Then I can just ssh in to each machine as root and run it from the shared directory.

Thanks for all your suggestions.
 
  


Reply

Tags
ssh


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
ssh and bash script question babag Linux - Networking 4 06-28-2008 01:26 AM
running bash scripts over ssh connection babag Linux - Newbie 1 05-28-2008 12:07 AM
ssh session within a bash script Tamaros Programming 1 05-11-2008 04:38 AM
Bash script to test if I can SSH to a server? DanHulton Linux - General 2 05-18-2007 02:42 PM
running su from a bash script caminoix Programming 7 12-28-2005 04:41 PM


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