1833044 Members
2602 Online
110049 Solutions
New Discussion

SSH Issue

 
pareshan
Regular Advisor

SSH Issue

I am wondering if there is any exception Handling in korn shell. I have one situation here, this is realted to my previous thread little bit if anybody who have gone through that.
I have big list of servers and I have to loop through all the servers and extract some data needed, everything else is working fine but

When i do
___________
ssh $i "some commands" #$i=server_name
it ask for password for some of the servers out of many
______________
I do understand, some of the servers from the list may not be valid or some of the servers many not have ssh set up for my account or any account
________
but how can i skip those situations because my program just stuck asking for password. I want if that happens then go for the next server in the list and put the name of those not working ones in some other text file or log file.
Here the code I have
_______________

#!/usr/bin/ksh
req_info()
{
for i in ` cat server_list_old`
do
echo $i
if [ $i = "bhpflp1a" ]
then
continue
fi
ssh $i grep $i /usr/local/syncsort_3.4/license.dat > tmp1
if [ $? = 0 ]
then
ssh $i "cd /usr/local/syncsort_3.4/bin/;./sysenv|grep CPUs">tmp2
echo $i ` awk '{print $4, $5}' tmp1` permanent `awk '{print $1,$2,$3,$4,$5}' tmp2`| tee -a result
else

ssh $i "cd /usr/local/syncsort_3.4/bin/;./sysenv|grep CPUs">>tmp2
ssh $i grep SyncSort /usr/local/syncsort_3.4/license.dat > tmp1
echo $i `awk '{print $4, $5}' tmp1` temporary `awk '{print $1,$2,$3,$4,$5}' tmp2`| tee -a result
fi
done
rm -f tmp2 tmp1
}

req_info
__________________
Here, you can see I can skip the servers if I know in advance but I wont know in the beginning for most of the case, situation can be like the working server may have some problems sometime and ask for password also. Just trying to handle the situation.

Any Idea Plz
Thank You,
Any Help will be appreciated



5 REPLIES 5
Ganesan R
Honored Contributor

Re: SSH Issue

Hi,

You should enable passwordless login for your account in all the servers to use script to execute some commands on remote servers.

Best wishes,

Ganesh.
Ganesan R
Honored Contributor

Re: SSH Issue

Hi,

There are many threads available here on ssh password less login. you can search with ssh passwordless keywords.

One among is

http://forums12.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1221495337406+28353475&threadId=1223480
Best wishes,

Ganesh.
Roman Schmidt
Frequent Advisor

Re: SSH Issue

pareshan
Regular Advisor

Re: SSH Issue

Looks like you dint get me what I am saying, of course I dont need to provde password for most of them, better to say almost all of them but I am just thinking about the rare situation and very few servers,
I dont want my program to stuck asking for password, instead skil the servers which ask for password and put that servers name in a file so that I can trace later on.

Problem can be if the name of the server is not valid, then wont ask for password and stuck but says

ssh: Could not resolve hostname bhtokan: host nor service provided, or not known

I think its clear now.
I am talking about two situations
-----one ssh is not setup for certain servers and
------another invalid servername
Heironimus
Honored Contributor

Re: SSH Issue

Use the BatchMode option to suppress password prompts, "ssh -o 'BatchMode yes'". Any server that needs a password will simply fail.