Sponsored Content
Top Forums Shell Programming and Scripting While loop breaking when using "ssh" command inside Post 302894971 by Anupam_Halder on Friday 28th of March 2014 06:58:35 AM
Old 03-28-2014
While loop breaking when using "ssh" command inside

Hi ,

I am trying to read a list of hosts from a config file and trying to get file list from that host. For this I have used one while loop.
Code:
cat "$ARCHIVE_CFG_FILE" |  sed '/^$/d' | sed '/^#/d' | while read ARCHIVE_CFG
do 
    SOURCE_SERVER_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $1 }'`
    SOURCE_FOLDER_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $2 }'`
    LOAD_FILE_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $3 }'`
    ARCHIVE_FOLDER=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $4 }'` 
    ARCHIVE_DELAY=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $5 }'`
    TEMP_SFTP_FILE="census_.$$.sftp"

    step_message="checking config variables"
    if [ "$SOURCE_SERVER_NAME" = "" ] || [ "$SOURCE_FOLDER_NAME" = "" ] || [ "$LOAD_FILE_NAME" = "" ] || [ "$ARCHIVE_FOLDER" = "" ] || [ "$ARCHIVE_DELAY" = "" ] || [ "$TEMP_SFTP_FILE" = "" ]
    then 
        log 3 "$step_message"
    else
        log 5 "$step_message"
    fi

    log 5 "================================================="
    log 5 "SOURCE_SERVER_NAME\t:\t$SOURCE_SERVER_NAME"
    log 5 "SOURCE_FOLDER_NAME\t:\t$SOURCE_FOLDER_NAME"
    log 5 "LOAD_FILE_NAME\t\t:\t$LOAD_FILE_NAME"
    log 5 "ARCHIVE_FOLDER\t\t:\t$ARCHIVE_FOLDER"
    log 5 "ARCHIVE_DELAY\t\t\t:\t$ARCHIVE_DELAY days"
    log 5 "TEMP_SFTP_FILE\t\t:\t$TEMP_SFTP_FILE"
    log 5 "================================================="
    
        #Getting file archive list from remote server
    step_message="Getting file archive list from remote server"
    FILELIST=`ssh $SOURCE_SERVER_NAME find $SOURCE_FOLDER_NAME -type f -mtime +$ARCHIVE_DELAY | grep "$SOURCE_FOLDER_NAME/$LOAD_FILE_NAME"`
    echo $?
    
done

But when I am using the ssh command inside this while loop the loop is breaking and I am not getting any more file list of next host.

Can anyone please suggest what is the issue and how to overcome this?

ARCHIVE_CFG_FILE = config file containing multiple host details
log is a function for logging.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Breaking input with "read" command

In this post, Perderabo's script says echo 05/06/25 14:15:56 | IFS=" /:" read Y1 M1 D1 h1 m1 s1 which, if I am not wrong, will break the input into Y1, M1 et al. I tried the following in my code #! /bin/ksh # per.sh typeset -R2 HOUR=00 typeset -R2 MIN=00 typeset -R2 SEC=00 ... (2 Replies)
Discussion started by: vino
2 Replies

2. Shell Programming and Scripting

Need a Command To display "echo command value in loop" in single line.

Hi I want to display "echo command value in loop" in single line. My requirement is to show the input file (test_1.txt) like the output file (test_2.txt) given below. Input file :test_1.txt a1|b1|4|5 a1|b1|42|9 a2|b2|32|25 a1|b1|2|5 a3|b3|4|8 a2|b2|14|6 Output file:test_2.txt... (2 Replies)
Discussion started by: sakthifire
2 Replies

3. Shell Programming and Scripting

Breaking "while read" also breaks the parent process

Hi, I'm a bit confused. Maybe some master can explain to me what is happening. I have a program that starts issuing output about himself loading. I want to run it in another thread but I want to wait untill it's fully loaded. Program sample: $ cat myprogram echo "loading" echo "almost... (3 Replies)
Discussion started by: chebarbudo
3 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

How to increment date using "for loop" in format MMDDYY inside the shell script?

Need to increment the date from "currentdate + 90days" inside the for loop (i=1 to i=50) (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

6. UNIX for Dummies Questions & Answers

What is the significance of sh -s in ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh?

Please can you help me understand the significance of providing arguments under sh -s in > ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh (4 Replies)
Discussion started by: Sree10
4 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Bash - How to do a "read -p" inside a while loop?

Hi there guys! I was trying to do: while read line; do if ; then read -p "Press Enter to continue..." cont=0 fi echo $line let cont++ done < file.txt However, I have read that the read -p would not work in a while loop... I was wondering if there is any other way to... (2 Replies)
Discussion started by: rplae
2 Replies

9. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

10. UNIX for Beginners Questions & Answers

"Mv" command does not work in loop, but works manually

Hi there, this may be a beginner's error, but I've been unable to find a solution on my own and by googling, and now I am really stuck on it. I am simply trying to move directories called for example CAT_Run01.ica to a directory with the corresponding number, Run01, in the same directory. For... (2 Replies)
Discussion started by: andrevol
2 Replies
SSH-KEYSCAN(1)						    BSD General Commands Manual 					    SSH-KEYSCAN(1)

NAME
ssh-keyscan -- gather ssh public keys SYNOPSIS
ssh-keyscan [-v46] [-p port] [-T timeout] [-t type] [-f file] [host | addrlist namelist] [...] DESCRIPTION
ssh-keyscan is a utility for gathering the public ssh host keys of a number of hosts. It was designed to aid in building and verifying ssh_known_hosts files. ssh-keyscan provides a minimal interface suitable for use by shell and perl scripts. ssh-keyscan uses non-blocking socket I/O to contact as many hosts as possible in parallel, so it is very efficient. The keys from a domain of 1,000 hosts can be collected in tens of seconds, even when some of those hosts are down or do not run ssh. For scanning, one does not need login access to the machines that are being scanned, nor does the scanning process involve any encryption. The options are as follows: -p port Port to connect to on the remote host. -T timeout Set the timeout for connection attempts. If timeout seconds have elapsed since a connection was initiated to a host or since the last time anything was read from that host, then the connection is closed and the host in question considered unavailable. Default is 5 seconds. -t type Specifies the type of the key to fetch from the scanned hosts. The possible values are ``rsa1'' for protocol version 1 and ``rsa'' or ``dsa'' for protocol version 2. Multiple values may be specified by separating them with commas. The default is ``rsa1''. -f filename Read hosts or addrlist namelist pairs from this file, one per line. If - is supplied instead of a filename, ssh-keyscan will read hosts or addrlist namelist pairs from the standard input. -v Verbose mode. Causes ssh-keyscan to print debugging messages about its progress. -4 Forces ssh-keyscan to use IPv4 addresses only. -6 Forces ssh-keyscan to use IPv6 addresses only. SECURITY
If a ssh_known_hosts file is constructed using ssh-keyscan without verifying the keys, users will be vulnerable to attacks. On the other hand, if the security model allows such a risk, ssh-keyscan can help in the detection of tampered keyfiles or man in the middle attacks which have begun after the ssh_known_hosts file was created. EXAMPLES
Print the rsa1 host key for machine hostname: $ ssh-keyscan hostname Find all hosts from the file ssh_hosts which have new or different keys from those in the sorted file ssh_known_hosts: $ ssh-keyscan -t rsa,dsa -f ssh_hosts | sort -u - ssh_known_hosts | diff ssh_known_hosts - FILES
Input format: 1.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4 Output format for rsa1 keys: host-or-namelist bits exponent modulus Output format for rsa and dsa keys: host-or-namelist keytype base64-encoded-key Where keytype is either ``ssh-rsa'' or ``ssh-dsa''. /etc/ssh/ssh_known_hosts BUGS
It generates "Connection closed by remote host" messages on the consoles of all the machines it scans if the server is older than version 2.9. This is because it opens a connection to the ssh port, reads the public key, and drops the connection as soon as it gets the key. SEE ALSO
ssh(1), sshd(8) AUTHORS
David Mazieres <dm@lcs.mit.edu> wrote the initial version, and Wayne Davison <wayned@users.sourceforge.net> added support for protocol ver- sion 2. BSD
January 1, 1996 BSD
All times are GMT -4. The time now is 03:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy