Running set of commands in remote servers in shell script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Linux Running set of commands in remote servers in shell script

Hi
Wishing to all.

I am very new joined in an organization as a unix system administrator.

I need a help in preparing a script for a report.

i have a file contains all of the linux/ubuntu servers line by line around 140 servers.
Code:
vi servers.txt

nh01
nh02
nh03
bh01
bh04
-
-
:wq

Now, my script should provide the output like below...
Code:
Server    ping_status   ssh_status   Kernal                   uptime   login_users  
nh01       pingable       ssh able    2.6.18-371.4.1.el5   24 days  30
nh02       pingable       not able     -                           -           -

please help me for the above script.

i can able to write a separate scripts for pinging or not, ssh or not, but not able to take the output in a above format.

and also, if a server is not able to ssh ..then my script gets struck there itself...its not moving further....

Thanks
Kumaraswasmy


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 10-14-2014 at 06:06 AM..
# 2  
Where are you stuck? Show us what you tried and error msgs received.
# 3  
Hi Rudic,
Actually, i am able to prepare the scripts separatly ...for ping status ans ssh status ...

Code:
while read line
do
        ping -c 1 $line > /dev/null 2> /dev/null
        if [ $? -eq 0 ];then
                echo "$line is up"
        else
                echo "$line is down"
        fi
done < servers.txt


Code:
while read line
do
     ssh "$line" "uname -a; w|wc -l " < /dev/null
done < servers.txt

the above ssh script...if any server is not up, then the script is not moving further server...

mainly , i need the out put as i mentioned in the first post...

Thanks
kumaraswamy

Last edited by rbatte1; 10-14-2014 at 08:29 AM.. Reason: Changed ICODE to CODE
# 4  
Well, why then don't you run the ssh command only if the server is up? Like
Code:
...
if [ $? -eq 0 ]
    then
       printf "%s\t%s $line "pingable"
       ssh "$line" "uname -a; w|wc -l " < /dev/null
       ... error handling ...
       printf "\tssh-able"
    else
...

This User Gave Thanks to RudiC For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #809
Difficulty: Easy
The CSS3 RGB Hex Code for DarkOrange is #FF4500.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error running grep on Remote Servers

Im running the below command sshpass -p mypassword ssh -t user1@server2 /bin/bash -c 'echo "mypassword" | sudo -S -l; echo "$?#`grep -iE "user66|dbuser|tomcat|splunk|stash|jira|user2|docadmin" /etc/passwd`"; exit' Below is the error I get: Output: I run this command across a... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Shell script for remote servers

Hi , I have written a small script : set -x #!/bin/ksh for i in `cat /tmp/list` ( list contains remove servers ) do ssh -t $i << EOF uname -a cd ~user echo "Enter the dir >" read dir path=`ll -ld /home/user/"$dir"` if ; then echo "Dir exists " read rm $path else echo "no such... (9 Replies)
Discussion started by: kpatel786
9 Replies

3. Shell Programming and Scripting

Shell script to set user password to never expire in UNIX servers

Hi, I have a requirement where in i need to write a shell script to set users password to never expire. I know the command which is used to perform the same .. which is chage command. But, could not figure out how to do the same in shell script. Could you please help me with the shell... (3 Replies)
Discussion started by: suren424
3 Replies

4. Shell Programming and Scripting

Remote login and running a script on multiple servers

Hi all, I am baffled on this. Solaris Irix system.:confused: I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek: ... (10 Replies)
Discussion started by: weddy
10 Replies

5. Shell Programming and Scripting

Issue with running commands from shell script

I'm trying to copy files from a remote windows server to Unix server. I was successfully able to copy files from windows server using command prompt but when I run these commands from a script it's not working as expected. commands used: sftp user@remoteserver.com lcd local_dir cd... (3 Replies)
Discussion started by: naresh7590
3 Replies

6. Shell Programming and Scripting

Shell script help to execute ssh remote commands

Hi, The below command is not giving me the count , Can somebody help me in re-writing this pls . Proc_Exist=`ssh -q -o "BatchMode=yes" -o "PasswordAuthentication=no" $OAUSER@${Primary_Node} ps -ef | grep -v grep | grep "${ICM_Proc}" |wc -l ` Also the same problem with below... (13 Replies)
Discussion started by: Y.balakrishna
13 Replies

7. Shell Programming and Scripting

Shell script with mutiple steps/commands, on UNIX servers

Hi, I wrote a simple script, which will call other scripts or run commands on a UNIX server. my script has multiple steps/commands with some delay in between. I usually get some email notifications after the successful execution of each step. **My intention is to get email alerts when it is... (5 Replies)
Discussion started by: System Admin 77
5 Replies

8. Shell Programming and Scripting

Prevent wrong user from using shell script for multiple remote servers

Hi, I am running a shell script from a central server to multiple remote servers using the following code: application_check() { # Linux/UNIX box with ssh key based login SERVERS=`cat /tmp/server-details` # SSH User name USR="user" # create new file > /tmp/abc.log # connect... (2 Replies)
Discussion started by: mystition
2 Replies

9. UNIX for Dummies Questions & Answers

Running the same remote script on multiple servers

Experts, Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file. I struggled with this yesterday & finally that script is working now. Now, here is a scope creep and the script that I wrote for 1 remote... (2 Replies)
Discussion started by: OMLEELA
2 Replies

10. Shell Programming and Scripting

unix shell script which inserts some records into a file located in remote servers...

All, I need to write an unix shell script which inserts some records into a file located in remote servers. * Get the input from the user and insert according the first row. It should be in ascending order. 123451,XA,ABA 123452,XB,ABB 123453,XC,ABC 123455,XE,ABE 123456,XF,ABF 123458,XG,ABG... (2 Replies)
Discussion started by: techychap
2 Replies

Featured Tech Videos