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.

vi servers.txt

nh01
nh02
nh03
bh01
bh04
-
-
:wq

Now, my script should provide the output like below...

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

Where are you stuck? Show us what you tried and error msgs received.

Hi Rudic,
Actually, i am able to prepare the scripts separatly ...for ping status ans ssh status ...

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
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

Well, why then don't you run the ssh command only if the server is up? Like

...
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
...
1 Like