LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ssh: connect to host .....No route to host (http://www.linuxquestions.org/questions/linux-newbie-8/ssh-connect-to-host-no-route-to-host-764778/)

soumyacs 10-27-2009 07:55 AM

ssh: connect to host .....No route to host
 
Hi All,

I am exceuting a script file after connecting a server using ssh .

ssh -f <IPADDRESS1> '/root/Desktop/a.sh &'


ssh -f <IPADDRESS2> '/root/Desktop/a.sh &'

....................


Now Out of 10 ips , 7 ips are connected. For rest of the ips (ie 3) it is showing
ssh: connect to host .....No route to host

and I am not able to put this connection error in a log file.


So , I want a solution that will produce an error/alert message if the ip is not connected as for rest of the ips the script file is being executed properly and getting the desired result.....

Thanks in advance

Agrouf 10-27-2009 08:03 AM

To put the error to a log file, append this to your ssh command:
Code:

ssh -f <IPADDRESS1> '/root/Desktop/a.sh &' 2>loggile.log

soumyacs 10-27-2009 09:07 AM

Thanks... But I need the output also in that log file(of that file of those ips which got connected)

In that log file only error message is coming..

I want to know one thing-----------

if [ <ssh -f <IPADDRESS1> '/root/Desktop/a.sh &'> ] is true(got connected and executed)
then
"connected"
else
"not connected"


is it possible to write this type of code in shell script ??

Agrouf 10-27-2009 09:25 AM

do it like this:
Code:

if ssh -f <IPADDRESS1> '/root/Desktop/a.sh &'; then
  echo "connected"
else
  echo "not connected"
fi


soumyacs 10-27-2009 09:48 AM

Thanks it is working.

Can you pls tell me how to put this value( either connected or not connected) in to a varible??


I tried this one but is not working....

variable = `if ssh -f <IPADDRESS1> '/root/Desktop/a.sh &'; then
echo "connected"
else
echo "not connected"
fi`


Can you pls tell me the code??

Thanks in advance

Agrouf 10-27-2009 10:03 AM

Code:

if ssh -f <IPADDRESS1> '/root/Desktop/a.sh &'; then
  variable="connected"
else
  variable="not connected"
fi
echo "variable is $variable"



All times are GMT -5. The time now is 10:33 PM.