Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute Commands on Multiple UNIX Servers

Status
Not open for further replies.

unixscm

Programmer
Jun 9, 2010
2
US
Hi all,

I have 6 unix servers, i want to execute same command on the 6 unix servers.

I want a script which i will run from one machine to start and stop the remote services.

manual process
ssh ipaddress
cd /usr/scripts
ls -l

I want to automate this process thru script, i created the key gen to by pass the passowrd step.

i want in the script(test.sh)
like
ssh ipaddress
cd /usr/scripts
$1

where i want to pass the $1 from command prompt.

test.sh ls-l or test.sh df -k

i tried to write the script, i have problem in simulating the ENTER key press and append the next command after ssh ipaddress.

can you please help.

Thanks.








 
If you enclose the commands to run over ssh in double quotes like this it should do the trick.

Code:
ssh ipaddress "
        cd /usr/scripts
        $1
"

However, note that if you pass ls -l, then only the ls part will be in $1, and the -l will be in $2. Maybe you would prefer to use $@, which includes all parameters supplied on the command-line.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top