Execute script from central server without uploading to remote machines
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
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 ?
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...
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 ?
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.