LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-26-2009, 11:02 AM   #1
zugly
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 0
Execute script from central server without uploading to remote machines


Hi, I have written a script that I want to execute on a number of remote machine from a central server, without having to upload to those machines. I know the script works if I do upload it and use ssh eg:

ssh <remote_server> "/tmp/file-to-run"

Is it possible to do ? Thanks,
 
Old 01-26-2009, 11:43 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by zugly View Post
Hi, I have written a script that I want to execute on a number of remote machine from a central server, without having to upload to those machines. I know the script works if I do upload it and use ssh eg:

ssh <remote_server> "/tmp/file-to-run"

Is it possible to do ? Thanks,
Hard to say, since you don't actually give any details about the machines in question, your script or what it does, or anything that would give us what we need to answer the question.

If your script is gathering information on the remote system, you may be able to cat files, grep for things, etc., via SSH commands, and return the results back to the 'central' system. Otherwise, you can put a 'self-destruct' command as the last line of the script, so after you copy it to the remote system, it can execute and remove itself after it's done.
 
Old 01-26-2009, 12:24 PM   #3
zugly
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your reply.

The script is a shell script thats intention is to check the status of the remote systems by running some standard commands such as checking disk space usage, tailing some log files, checking the status of processes running etc....... I want to avoid having to upload it to the remote servers, is it possbile to remotely execute the script ?
 
Old 01-26-2009, 12:35 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
Quote:
I want to avoid having to upload it to the remote servers
I don't understand why you "want to avoid having to upload it", once it is uploaded, it'll be easy to run any time.
 
Old 01-26-2009, 12:38 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by zugly View Post
Thanks for your reply.

The script is a shell script thats intention is to check the status of the remote systems by running some standard commands such as checking disk space usage, tailing some log files, checking the status of processes running etc....... I want to avoid having to upload it to the remote servers, is it possbile to remotely execute the script ?
Well, you still don't say alot about your script, or how it works.

If you want to gather those things using standard linux commands, they'll have to be run on the remote system. As I said, you CAN use SSH to run a command (like "df -kPH"), and get the results locally. Since these are your servers, uploading a script once, to run many times, isn't that big of a deal.

You CAN use SNMP queries to get alot of that information, with the exception of tailing log files. However, you can also use syslog-ng to 'centralize' your log files...
 
Old 01-26-2009, 06:22 PM   #6
zugly
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 0
As i said my script runs commands like checking disk space, processes that are running, returning output from log files.....
eg:
df -h
tail -n 10 /var/log/messages

I know that uploading the script is the easiest option as I have already got it running and producing the output I want. However my question was if its possible to have this script on a central server and execute it on a number of other remote servers ?
 
Old 01-27-2009, 09:23 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by zugly View Post
As i said my script runs commands like checking disk space, processes that are running, returning output from log files.....
eg:
df -h
tail -n 10 /var/log/messages

I know that uploading the script is the easiest option as I have already got it running and producing the output I want. However my question was if its possible to have this script on a central server and execute it on a number of other remote servers ?
No, you can't.

However, as I said earlier, you can use SSH WITHIN your script, on a central box, to run those commands.

Something like:

ssh <user>@<server> "df -kPH" >> output.file
ssh <user>@<server> "tail -n 10 /var/log/messages" >> output.file

That may work for you. I know in Perl it's easy to open SSH connections and get this output into a variable, but don't know a good way to do it in bash. And SNMP can work also, for pretty much everything but the log file tail, but you can get your logfiles to go to a central spot.

I don't think you can do it the way you're wanting to, but you do have options.
 
Old 03-18-2009, 12:39 PM   #8
jonez
LQ Newbie
 
Registered: May 2008
Posts: 3

Rep: Reputation: 0
Quote:
Originally Posted by zugly View Post
As i said my script runs commands like checking disk space, processes that are running, returning output from log files.....
eg:
df -h
tail -n 10 /var/log/messages

I know that uploading the script is the easiest option as I have already got it running and producing the output I want. However my question was if its possible to have this script on a central server and execute it on a number of other remote servers ?
You can use expect within a bash script. Expect will run the commands that you give it on the remote host. Here's a quick example, this was made using autoexpect so this could be cleaned up further:

Code:
#!/bin/bash
#!/usr/bin/expect

REMOTE_HOST ()
{
echo "This script will change a file on a remote host using bash and expect."
/usr/bin/expect - << EndMark
spawn ssh YOURREMOTEHOST
sleep .5
expect -- "password: "
send -- "YOURPASSWORD\r"
sleep .5
expect -- "\]\$ "
send -- "touch /tmp/testing\r"
expect -- "\]\$ "
send -- "echo \"This is being performed on the remote host's files\" > /tmp/testing\r"
expect -- "\]\$ "
send -- "echo \"All expect commands will continue to be run on this remote host until we log out\" >> /tmp/testing\r"
expect -- "\]\$ "
send -- "logout\r"
sleep .5
send -- "Expect has now finished successfully!"
EndMark
echo "Creating a file on the remote host is now done!"
}
REMOTE_HOST
 
  


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
Executing a script when uploading a file to a SAMBA SERVER rafa_gallego Linux - Server 4 01-18-2008 06:39 AM
perl script to execute my a c executable on remote machin sharad Linux - General 5 12-14-2006 08:56 AM
remote execute a bash script vmware Linux - Enterprise 3 09-07-2006 04:01 PM
Remote Script execution from the central location anil_garg5 Linux - General 5 05-11-2006 04:29 PM
Remote Win Bat File execute Shell Script on AIX Server DriveMeCrazy AIX 5 05-26-2004 07:24 PM


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