Create a list of commands in a central location, and then run them all remotely through a ssh here


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a list of commands in a central location, and then run them all remotely through a ssh here
# 1  
Old 09-22-2010
Create a list of commands in a central location, and then run them all remotely through a ssh here

I'm trying to write a script that in the end will from one central location hop to a bunch of servers and then run a series of ping tests. The thing is, the list of devices that needs to be pinged is going to be different for each server. So what I want to do is be able to do is read through the list of servers at the central location, set up the logic to figure out what machines it needs to ping, and then execute a single ssh session with a here statement. The issue I have is, I'm not sure how to create a list of commands, and then run through them.

So what I have right now is:

Code:
#!/bin/bash

head -1 blade | while read i; do
    i=($i)
    case "${i%b*}" in
        r01)
                        #LOGIC TO DETERMINE WHAT SERVERS NEED TO BE PINGED GOES HERE
            ssh -T r01b01  <<EOF
                        #ACTUAL COMMANDS GO HERE INSTEAD OF SINGLE PING COMMAND BELOW
ping -q -c 1 -w 1 10.250.19.5 > /dev/null && echo "success" || echo "failed"
EOF
        ;;
        esac
    done

Doing the logic is fine, I can hack my way through that. What I can't figure out is how to pass a list of commands based on that logic through a single ssh connection.

Any ideas?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can i create a script that will ssh a device and type some commands?

Hi Guys, this is the scenario: ubuntu pc and I have 10 wireless devices that I need to check their firmware version. I would like to create a script that it will ask me IP, after I enter it, I hit enter then it will show me the version of the firmware. this is what i do. ssh... (9 Replies)
Discussion started by: gabak
9 Replies

2. Shell Programming and Scripting

How to run commands on remote server using ssh password less authentication?

Hi, I need to run a script located in a directory on remote server by using ssh authentication from my local unix server. Can anyone help me in this. I have tried the below command. It worked for echo command but when i tried to open a file using cat command it is showing "cat: cannot open... (6 Replies)
Discussion started by: ssk250
6 Replies

3. Shell Programming and Scripting

How to automatically run commands after SSH and SUDO not working?

I'm working on a script to SSH and SUDO as (sap user sidadm) then automatically run commands that the sidadm user can run such as R3trans -v, tp, etc.. I can SSH without password and SUDO.. but the commands don't run after I SSH and SUDO to the sidadm user...here is the commands that I've... (2 Replies)
Discussion started by: icemanj
2 Replies

4. Shell Programming and Scripting

Run multiple commands in ssh

Hi All, I have the below requirement. I want to copy the local file to remote after that i need to run the local script on a remote machine.When i use two ssh commnds i can achieve this. But i want to achieve this using one ssh command. Below command to copy the local file to remote ssh -q... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

5. UNIX for Dummies Questions & Answers

To run 5 commands at the same time with process from a list

I have many command is list in the variable lists,each command will run a very long time, so I want to run 5 commands at the same time with process till it complete run all the command, lists="aa bb cc dd xx gg blabla zz ......." ( a very long list) can some one point me the codes? ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

6. UNIX for Dummies Questions & Answers

How to save and run a list of commands?

Dear every one, I am working with the data of my lab program and I have to do many times by the same list of some commands (grep, then save to file, then use awk to delete odd lines, save to file, use awk to delete even lines, save to file...). Is there any way to save a list of command which I... (4 Replies)
Discussion started by: phamnu
4 Replies

7. AIX

List of AIX commands that can be run by ROOT user ONLY

Hello, I am testing sudo and I want to test it. Can anyone please let me know few commands (of course other than shutdown, reboot etc. as I can't reboot the box) on AIX that can be run by ROOT only. Thanks ---------- Post updated at 07:43 PM ---------- Previous update was at 07:38 PM... (5 Replies)
Discussion started by: prvnrk
5 Replies

8. AIX

How to create - Central access printer..

Guys, Totally new to this... I have asked to create a Central access printer to an AIX Server.. Spoolserver : SapErpDev_DEV_00 Host : SapErpDev IP : 172.30.1.17 Device type : HPLJ4 Printer model - HPLJ 4 : HP laserjet 4 series PCL - 5 Question.. From my understanding, I... (3 Replies)
Discussion started by: mushr00m
3 Replies

9. UNIX and Linux Applications

Central Location for all ssh Keys and Settings Unattended Secure File Transfer

I am developing an application that submits command line file transfers using ssh (Sun to Sun) and Tectia ssh (Sun to Windows Server) embedded in the code. Potentially many different trusted people will start the programs. Is there a way to have all the settings and keys localized so that there is... (0 Replies)
Discussion started by: PowersThatB
0 Replies

10. Shell Programming and Scripting

How to run a set of commands through ssh

I need to run a set of commands on a remote machine using ssh. it should also collect output and return status of each command. Can someone help me how to do this? (1 Reply)
Discussion started by: vickylife
1 Replies
Login or Register to Ask a Question