Command to check if the server is not reachable using ssh


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Command to check if the server is not reachable using ssh
# 1  
Old 10-01-2015
Command to check if the server is not reachable using ssh

I have list for servers say server1, server2, server3.....server20
I want to test the ssh connectivity of each server, if any one of the server is down then ssh connectivity fails and the script results something like echo "serever is not reachable"

Now I m confused using which command shall I check if the server is not reachable using ssh,
can any one suggest the best solution for this so that I can add it in my code

below are the two command I found and how it works:
command1:
success case:
Code:
ssh -q user@$server1 exit

bash-3.00$ echo $?
0
failure case:
Code:
ssh -q user@$server1000 exit

bash-3.00$ echo $?
255

command2:
success case:
Code:
ssh -o ConnectTimeout=3 user@$server1 exit

bash-3.00$ echo $?
0
failure case:
Code:
ssh -o ConnectTimeout=3 user@$server1000 exit

ssh: server1000: node name or service name not known
bash-3.00$ echo $?
255
# 2  
Old 10-01-2015
What's the confusion exactly? You've found not one but several ways that work...
# 3  
Old 10-01-2015
I have below three commands can you suggest which is the best and secured, or any other alternate solution for this

Code:
ssh -q user@$server1 exit

Code:
ssh -o ConnectTimeout=3 user@$server1 exit

Code:
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 user1@server1


Last edited by sam@sam; 10-01-2015 at 02:14 PM..
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 to check via SSH and credentials if file on remote server exists?

Hi there, I am sorry to ask that kind of beginner thing, but all the code I found online didnt work for me. All I want to do is: Check via SSH if a File exists on my webserver. The SSH login has to be with username and password. So I would be very thankful if somebody could write the line.... (8 Replies)
Discussion started by: Jens885544
8 Replies

2. Shell Programming and Scripting

Send command via ssh to another server

Hello, i`m tryeing to execute loop on remote server and i have problems with syntax my command is ssh root@server "for i in /vz/private/*; do b=`ls -la $i/usr/bin/crontab | awk '{print $1}'`; echo $b; done" with this command i`m tryeing to get all permissions of file /usr/bin/crontab... (1 Reply)
Discussion started by: bacarrdy
1 Replies

3. Shell Programming and Scripting

Execute command using ssh server 'cmd'

Hi The command below does not work as it require to take command in the breakers But If I do so the variable values get lost ssh testserver01 'dsmc q b "${ARCHIVE_DIR}*" -sub=yes -querysummary -inactive -fromd="${BACKUP_DATE}"' Thank you. (3 Replies)
Discussion started by: zam
3 Replies

4. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

5. Shell Programming and Scripting

ssh to remote server and check if file exists

Hi everyone, I am trying to figure out a way to ssh to remote server and check if file exists, and if it doesn't I want to leave the script with an exit status of 5. I have the following that I am attempting to use, but it is not returning anything: check() { ssh ${SOURCE_SERV} "ls -l... (4 Replies)
Discussion started by: jimbojames
4 Replies

6. UNIX for Dummies Questions & Answers

ssh command to execute shell script in another server

ssh -q <hostname> /opt/tcs/satish/tst.ksh ssh -q <anotherserver> /opt/tcs/satish/tst.ksh tst.ksh has "nohup <command> & " when i execute below script , its throwing error as nohup can not be found ssh -q <anotherserver> /opt/tcs/satish/tst.ksh > log & can someone let me... (5 Replies)
Discussion started by: only4satish
5 Replies

7. UNIX for Dummies Questions & Answers

Command to check unix have web server

Hye All Any body know what is command to check whether unix have web server. (3 Replies)
Discussion started by: mastercar
3 Replies

8. Fedora

ssh command to read server resources

what is the ssh command to read my server resources, like system operator, Ram installed, CPU etc....? (12 Replies)
Discussion started by: dan8354544
12 Replies

9. Shell Programming and Scripting

how to connect to server with ssh to check process size

Hello i have to connect to 11 servers to check the process size on every server. how to that with shell scripting using ssh regards (7 Replies)
Discussion started by: mogabr
7 Replies

10. HP-UX

Command for check NFS Server.

Please Help, What cammand use to check sharing path on NFS Server. Thanks, :cool: (2 Replies)
Discussion started by: arm_naja
2 Replies
Login or Register to Ask a Question