How to avoid multiple ssh -o StrictHostKeychecking=no?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to avoid multiple ssh -o StrictHostKeychecking=no?
# 1  
Old 07-19-2013
How to avoid multiple ssh -o StrictHostKeychecking=no?

How do i avoid multiple ssh -o StrictHostKeychecking=no in the below script.

Code:
if [ "$#" == "0" ]
then
echo " Please mention the server name after the script"
elif ssh -o StrictHostKeychecking=no $1 "[ -d /abc/def/ ]" 2> /dev/null
then
ver=`ssh -o StrictHostKeychecking=no $1 "cat /abc/def/version" 2> /dev/null`
env=`ssh -o StrictHostKeychecking=no $1 "cat /abc/def/environment" 2> /dev/null`
echo "version name for server $1 is $ver"
echo "env name for server $1 is $env"
else
echo " /abc/def not present in the $1"
fi
exit 1


Last edited by Don Cragun; 07-19-2013 at 04:14 AM.. Reason: Reposition closing CODE tag.
# 2  
Old 07-19-2013
Well, you could run it once and read the responses. Try something like this and see if it gets you nearer to what you are after:-
Code:
if [ "$#" == "0" ]
then
   echo " Please mention the server name after the script"
   exit 1
fi

unset dir                        # Ensure we have nothing confusing already set in here

ssh -o StrictHostKeychecking=no $1 \
 "ls -1d /abc/def;
 cat /abc/def/version;
 cat /abc/def/environment" |\
  while read dir
  do
     read ver
     read env
  done

echo "Reference directory ${dir:-not} present on $1"
echo "version name for server $1 is ${ver:-"Not Set"}"
echo "env name for server $1 is ${env:-"Not Set"}"



I hope that this helps,

Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 07-22-2013
rbatte1 Image
Registered User

thank you rbatte1.

i did some modification and now the script is looking better than what i posted first Smilie. issue i faced with u r code dir variable is not getting the directory name and also i didn't wanted the last 2 line to be printed if the directory is not available.
This User Gave Thanks to NarayanaPrakash For This Post:
# 4  
Old 07-22-2013
Well, it's only a suggestion. You can of course modify it as you wish. Glad it helped, and thanks for letting us know.

Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Avoid multiple emails being sent - Counter, Loop?

Hello, I have currently coded a bash script below in which it does the following: # Archives compressed file from another location. Basically it moves *.gz files to another location. The script also sends an email whenever a new compressed file is placed. This is the issue that i... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

3. Shell Programming and Scripting

How to avoid ssh :Write failed: Broken pipe?

Hello, I am trying to run some code on Matlab over ssh . The code takes around 5-6 hours to complete. so after giving the command to run it , I locked my machine and then went off to sleep at night, only to discover in the morning that I get this message : ...Code running, partial results... (1 Reply)
Discussion started by: ajayram
1 Replies

4. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

5. Shell Programming and Scripting

how do i avoid system hang due to ssh in script?

I have a script that collects data from about 200 servers using 'ssh'. The problem is that, process sometime hangs at some point stopping the execution of the script. Please give me some idea how can I force the execution to jump to the next step if there arises any problem !! Thanks for replies if... (1 Reply)
Discussion started by: mdangol
1 Replies

6. Shell Programming and Scripting

Avoid script running multiple times by filelock

Sometimes we need a single instance of a script to run at a time. Meaning, the script itself should detects whether any instances of himself are still running and act accordingly. When multiple instances of one script running, it’s easy to cause problems. I’ve ever seen that about 350 instances... (4 Replies)
Discussion started by: edenCC
4 Replies

7. Shell Programming and Scripting

using SSH with my script and avoid logging in manually

Hi Guys. I have 3 variables $HOST $Username $Password I want to connect to a remote server using SFTP. usr/bin/sftp -o Cipher=blowfish $HostWhere do I put in the options for the username and pwd??? I have tried different ways and nothing works. It keeps coming back and promting me. ... (5 Replies)
Discussion started by: ramangill
5 Replies

8. Shell Programming and Scripting

How to avoid multiple while loop?

Hi, How can I avoid multiple 'cat while read ....? in my script. In my script, I am taking the inputs from the temp text file and doing the ( cat while read input do ... ... done ) task and deleting later. I know it'll raise the perfomance issue. How to avoid this? (2 Replies)
Discussion started by: sharif
2 Replies

9. UNIX for Dummies Questions & Answers

echo is suppressing multiple spaces.How to avoid it

I am reading a file and copying selected lines from the file into another using echo. For eg: while read line do if ((some logic to determine whether I need to copy the current line to another file)) then echo $line > tempfile fi done<srcfile The problem I have is the data in the file... (1 Reply)
Discussion started by: prathima
1 Replies
Login or Register to Ask a Question