Script to execute command to get info from multiple servers

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to execute command to get info from multiple servers
# 1  
Old 10-19-2012
Java Script to execute command to get info from multiple servers


I want to collect info from a no. of servers whether there grub.conf contain "elevator" parameter or not.

What I want is

sudo cat /etc/grub.conf | grep -q "elevator=noop"; echo $?

If output is "0", I want name of that host in a file called "present"
if its not "0", I want that hostname in a file called "not-present".

Now, Password less key authentication is something I can not do as of now. I am okay with specifying password in script.

Can someone please help me achieving this?
# 2  
Old 10-19-2012
Create a list of servers, call it servers.dat
> ./present
> ./not-present
while read node
      ssh $node 'sudo  grep -q  "elevator=noop" /etc/grub.conf'
      if [ $? -eq 0 ] ; then
         echo "$node" >> ./present
         echo "$node" >> ./not-present
done < servers.dat

This requires that your account be set up to sudo on all of the servers, and that you have set up ssh-keys (from the box where you execute the above script) for your account on all servers in the respective ~/.ssh/authorized_keys files.
# 3  
Old 10-19-2012
Thanks for the reply mate but We don't have key-authentication here,

I want to give password through the script. I guess it could be done through "except" but I dont know how to use except in script.
# 4  
Old 10-19-2012
You could use Expect to handle the password prompting.
# 5  
Old 10-19-2012
Following is my script :

export BASEDIR=/home/whoami

MyServer=cat $FILE

expect -c 'spawn ssh '$MyUser'@'$MyServer' ; expect password ; send "'$MyPassword'\n" ; 'sudo  grep -q  "elevator=noop" /etc/grub.conf' '

      if [ $? -eq 0 ] ; then
         echo "$node" >> ./present
         echo "$node" >> ./not-present

It never got executed, I just got a million "y" as o/p on screen. Ignore this error .. please tell me what is wrong with script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

One Line Command how to use pipe statements to execute and comment on multiple possible outcomes

Hello Forum, I'm looking to expand the following command: INACTIVE_KERNELS=$(python -mplatform | grep -qi red && rpm -qa | grep '^kernel-' |grep -vE `uname -r` | paste -sd \; || echo "Not Red Hat Server") Currently this command will check if my server is RedHat server using the grep -qi... (6 Replies)
Discussion started by: greavette
6 Replies

2. Shell Programming and Scripting

How to run simple single command on multiple Linux servers?

Hi All, How can i run a single command on multiple servers with or without giving credentials. I have a file(servers.txt) which has got list of servers and i want to run a command lsb_release -dr on all these servers and get output of those servers against each server. I tried below code... (9 Replies)
Discussion started by: darling
9 Replies

3. Shell Programming and Scripting

Run a script on multiple servers

I need to run a script on a bunch of remote servers. how can this be done without ssh into each individual server and run it its under /sbin/ on each server (1 Reply)
Discussion started by: tdubb123
1 Replies

4. Shell Programming and Scripting

Logging in to multiple Linux servers and running the command.

Hi, I am trying to write a script to run a command on multiple linux based servers and get the o/p. I am using ssh to login. It is a celerra box and EMC NAS product. I am able login but i am not able to run nas command nas_pool -size -all the NAS server. I am getting the following error. ... (2 Replies)
Discussion started by: jpkumar10
2 Replies

5. Shell Programming and Scripting

Require single command to start script in multiple servers

I have 9 servers, on each server a script with common name is available. I send a token file to all server from 1 particular server. so when a daemon job checks that token file is available then it triggers the script.. I want to know is there any command or script which I will run/execute on... (16 Replies)
Discussion started by: mirwasim
16 Replies

6. Shell Programming and Scripting

Script for login to servers with user name and password and execute commands

I am having the 15 servers which need to do the monitoring Hi I need a shell script, By which i can log in to multiple servers and execute the commands.. I need to specify the username and password in the scripts. Please help me to write the script so that it can login with username and... (5 Replies)
Discussion started by: nandan8a
5 Replies

7. Shell Programming and Scripting

bash script to execute a command remote servers using ssh

Hello, I am running into few issues, please suggest me what I am missing. I am running this script on a linux host. Main idea of this script is to, login to each host via ssh and get uid of user, service user that I trying to run this script, has already deployed ssh keys and provide sudo... (8 Replies)
Discussion started by: bobby320
8 Replies

8. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

9. Shell Programming and Scripting

Script ftp multiple servers

Hi guys , i have 1 problem and no find what is the problem...:confused:, and .netrc is configured and correct permissions... REMOTE="/home/user" LISTADO=`cat /root/home/user/LISTADO.txt` MACHINE=$(echo $i|awk 'FS="|" {print $1}') for i in $LISTADO do ftp $MACHINE <<TER passive prompt... (2 Replies)
Discussion started by: Esquizo000
2 Replies

10. Shell Programming and Scripting

login into multiple servers thru script...

I need to login into multiple servers thru a script run couple commands and run find command as root. I only have ssh access to the servers as a user than I can "su" to root. If you have a similar script please post it. Also if you can suggest commands that I should consider please let me know. ... (1 Reply)
Discussion started by: avcert1998
1 Replies
Login or Register to Ask a Question

Featured Tech Videos