LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-09-2011, 03:37 PM   #1
geek12
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Rep: Reputation: Disabled
A scripting question


Hi,

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.

Thanks.
 
Old 11-09-2011, 03:44 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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
 
Old 11-09-2011, 03:45 PM   #3
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by geek12 View Post
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).

[X] Doc CPU
 
Old 11-09-2011, 04:44 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Doc CPU View Post
Hi there,



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.
 
Old 11-09-2011, 06:24 PM   #5
geek12
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by macemoneta View Post
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?

Thanks.
 
Old 11-09-2011, 06:46 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
http://www.linuxquestions.org/questi...lancer-800668/
 
Old 11-09-2011, 07:16 PM   #7
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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.
 
  


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
Scripting Question brownwrap Programming 10 02-16-2011 01:32 PM
Scripting question mithereal Linux - General 2 09-21-2005 02:02 AM
Scripting Question Darklight451 Linux - Newbie 4 11-12-2004 11:14 AM
Scripting Question caps_phisto Linux - General 1 11-05-2004 02:43 PM
Scripting question aikitortoise Linux - Newbie 3 11-14-2002 05:18 PM

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

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