ssh to another computer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh to another computer
# 1  
Old 11-14-2008
ssh to another computer

I was wondering if there is a way to make an if statement to check if a computer is online.
something like
if comp1 is on
ssh -X [comp1]
else
ssh -X [comp2]
# 2  
Old 11-14-2008
try a ping <hostname> ..ping once ..awk the result and
save it into varibale and check that in IF condition.
# 3  
Old 11-14-2008
one way:
Code:
ping remotenode -n 1 -m 3

if [[ $? -eq 0 ]] ; then
         echo "remote node up"
else
         echo "remote now down"
fi

# 4  
Old 11-14-2008
Quote:
Originally Posted by jim mcnamara
one way:
Code:
ping remotenode -n 1 -m 3
 
if [[ $? -eq 0 ]] ; then
         echo "remote node up"
else
         echo "remote now down"
fi

What is -m ?

My CentOS 5.2 doesnot support -m

This worked for me:
Code:
# -c 1 = Send only 1 ping
# -W 2 = 2 second timeout

ping $1 -c 1 -W 2 > /dev/null

if [[ $? -eq 0 ]] ; then
         echo "remote node up"
else
         echo "remote now down"
fi


Last edited by Ikon; 11-14-2008 at 05:39 PM..
# 5  
Old 11-14-2008
ping doesn't play fair: -W and -m are for timeout and seem to depend on which family your unix derives from. -W is BSD. ping is not standardized, at least my POSIX guide doesn't show it being so.
# 6  
Old 11-14-2008
Thank you for all the help! it worked out just great!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find active SSH servers w/ ssh keys on LAN

Hi, I am trying to complete my bash script in order to find which SSH servers on LAN are still active with the ssh keys, but i am frozen at this step: #!/bin/bash # LAN SSH KEYS DISCOVERY SCRIPT </etc/passwd \ grep /bin/bash | cut -d: -f6 | sudo xargs -i -- sh -c ' && cat... (11 Replies)
Discussion started by: syrius
11 Replies

2. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

3. Shell Programming and Scripting

Ssh cat file output into a file on local computer

Hello, I'm on a remote computer by SSH. How can I get the output of "cat file" into a file on the local computer? I cannot use scp, because it's blocked. something like: ssh root@remote_maschine "cat /file" > /locale_machine/file :rolleyes: (2 Replies)
Discussion started by: borsti007
2 Replies

4. Shell Programming and Scripting

Check if file exists via ssh in ssh (nested)

I'm using redhat and have an odd issue with a nested ssh call. ssh -i ~/.ssh/transfer-key -q transfer@fserver1 ] && ssh -i ~/.ssh/transfer-key transfer@fserver1 "ssh -i ~/.ssh/sftp-key sftpin@10.0.0.1 ]" && ssh -i ~/.ssh/transfer-key transfer@fserver1 "scp -i ~/.ssh/sftp-key /home/S/outbox/*... (2 Replies)
Discussion started by: say170
2 Replies

5. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

6. Shell Programming and Scripting

Ssh = ssh expect and keep everything not change include parameter postion

I have write a script which contains ssh -p 12345 dcplatform@10.125.42.50 ssh 127.0.0.1 -p 5555 "$CMD" ssh root@$GUEST_IP "$CMD" before I use public key, it works well, now I want to change to "expect", BUT I don't want to change above code and "parameter position" I can post a... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

7. Shell Programming and Scripting

Using ssh to add register key on ssh server

Hi, I want to use ssh to add a register key on remote ssh server. Since there are space characters in my register key string, it always failed. If there is no space characters in the string, it worked fine. The following is what I have tried. It seems that "ssh" command doesn't care about double... (9 Replies)
Discussion started by: leaftree
9 Replies

8. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

9. UNIX for Advanced & Expert Users

who - PC Computer name

Does anyone know of a way of identifying the PC / client name rather than IP address via who or some other AIX command (5.3). (4 Replies)
Discussion started by: gefa
4 Replies
Login or Register to Ask a Question