Linux / UNIX Tech Support Forum
This is a discussion on run script on remote machine within the Shell scripting forums, part of the Development/Scripting category; Hello, I use a script to run commands on several servers. manually add the key exec ssh-agent bash ssh-add /root/.ssh/key ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello,
I use a script to run commands on several servers. manually add the key exec ssh-agent bash ssh-add /root/.ssh/key then run the script: SERVERS="server1 server2 server3 ..." for b in $SERVERS do echo $b; ssh -tq $b echo "test message $HOSTNAME" |mail mail @... -s "tstmsg"; done usually running a grep works great, but the above command fails, more exactly repeats for each SERVERS on the server it is being ran, and not on the remote machine. what would be the solution? any other optimization to the above would be appreciated. regards, |
| Sponsored Links | ||
|
|
|
||||
|
Try something like this. I used 2 test servers.
Run it like this: Here is the script. Code:
Prompt>./script.sh w Code:
#!/bin/bash
if [ -z "$1" ]; then
echo -e usage: "Command \n"
exit
fi
#loop through servers executing commands
for server in "radio25" "radio27" ;
do
echo -e "$server \n"
ssh -l root $server "$1"
done
Code:
[root@radio5 bin]# ./jason.sh w radio25 19:20:03 up 260 days, 7:30, 0 users, load average: 0.58, 0.85, 0.79 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT radio27 19:20:03 up 260 days, 9:01, 0 users, load average: 0.69, 0.63, 0.64 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT [root@radio5 bin]# Code:
[root@radio5 bin]# ./script.sh "echo testing >> jason*" radio25 radio27 Code:
[root@radio25 ~]# cat jason1 testing [root@radio25 ~]# Code:
[root@radio27 ~]# cat jason2 testing [root@radio27 ~]# HTH, Jaysunn Last edited by jaysunn; 29-10-2009 at 05:10 AM. |
|
||||
|
Well,
A little birdie told me to check your mail command. It appears to be repeated twice. This may be your issue. Try this. Code:
SERVERS="server1 server2 server3 ..." for b in $SERVERS do echo $b; ssh -tq $b echo "test message $HOSTNAME" |mail mail @... -s "tstmsg"; done Remove the mail in red. And try again. Everything else looks good. HTH, Jaysunn |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script for Linux Machine in Windows Network | imran83 | Shell scripting | 1 | 02-06-2009 04:36 PM |
| Script to delete a set of files in Remote machine | ashok333 | Shell scripting | 4 | 09-05-2008 07:24 PM |
| script hangs when a remote server is down | vikas027 | Shell scripting | 2 | 11-11-2007 03:47 PM |
| Shell script to perform operation on remote server | vivekv | Shell scripting | 3 | 24-10-2007 12:10 AM |
| Shell script to check the disk space on remote systems | vijayscripts | Shell scripting | 5 | 21-10-2007 06:29 PM |