ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I am still very new to scripting and learning. I have a very basic question. How do I run commands remotely. For example, if I am on server x and want to run a set of commands on server y and z, how can I do that without having to log on to each of them. Basic commands like looking for a user in /etc/passwd file in each server etc.
How do I run commands remotely. For example, if I am on server x and want to run a set of commands on server y and z, how can I do that without having to log on to each of them.
you can't. It's that simple.
If you want to run commands (i.e. programs) on a unix-like machine, you have to log on to that machine - preferrably via ssh. That means, you need to have a user account on that host (which can be a generic one, of course).
you can't. It's that simple.
If you want to run commands (i.e. programs) on a unix-like machine, you have to log on to that machine - preferrably via ssh. That means, you need to have a user account on that host (which can be a generic one, of course).
[X] Doc CPU
Well, maybe you can. If the remote hosts have processes monitoring requests and if there is a way to send a request to the remote hosts.
A way to send request is to, say, create or modify a file, and for that there should exist NFS mounts.
Or remote hosts can listen on a port using sockets.
Most Linux systems use ssh. You can pass a command for execution on a remote system, without starting a terminal session. For example:
Code:
ssh someuser@somesystem grep somebody /etc/passwd
Thanks. The above command worked. Now my question is how can I do routine to multiple servers, possibly with one command. I know I can probably do ssh someuser@somesystem grep somebody /etc/passwd;ssh someuser@somesystem1 grep somebody /etc/passwd ; and so on .. but if there is a quicker way to do this that would be great. For example, I can have a file with a list of systems in it and then have a for loop read thru that file, one system at a time. I dont know how to put this into code, but I thought that might work?
The pssh (parallel ssh) command can perform the function you're looking for. It can send the same commands to multiple systems and report or collect to files the responses. It's available in most distribution's repositories.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.