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
SEIVOTS-SUMMARY(1)					      General Commands Manual						SEIVOTS-SUMMARY(1)

NAME
seivots-summary - summarize seivot output files SYNOPSIS
seivots-summary [--config=FILE] [--dump-config] [--dump-memory-profile=METHOD] [--dump-setting-names] [--generate-manpage=TEMPLATE] [-h] [--help] [--list-config-files] [--log=FILE] [--log-keep=N] [--log-level=LEVEL] [--log-max=SIZE] [--log-mode=MODE] [--no-default-configs] [--output=FILE] [--version] [FILE]... DESCRIPTION
seivots-summary reads some benchmark result files created by summain(1), and produces summaries of them in tabular form, making it easy to compare results from different benchmark runs. OPTIONS
--config=FILE add FILE to config files --dump-config write out the entire current configuration --dump-memory-profile=METHOD make memory profiling dumps using METHOD, which is one of: none, simple, meliae, or heapy (default: simple) --dump-setting-names write out all names of settings and quit --generate-manpage=TEMPLATE fill in manual page TEMPLATE -h, --help show this help message and exit --list-config-files list all possible config files --log=FILE write log entries to FILE (default is to not write log files at all); use "syslog" to log to system log, or "none" to disable log- ging --log-keep=N keep last N logs (10) --log-level=LEVEL log at LEVEL, one of debug, info, warning, error, critical, fatal (default: debug) --log-max=SIZE rotate logs larger than SIZE, zero for never (default: 0) --log-mode=MODE set permissions of new log files to MODE (octal; default 0600) --no-default-configs clear list of configuration files to read --output=FILE write output to FILE, instead of standard output --version show program's version number and exit EXAMPLE
To summarize all benchmark files: seivots-summary $HOME/obnam/benchmarks/*/*.seivot | less -S SEE ALSO
seivot(1), obnam(1). SEIVOTS-SUMMARY(1)
All times are GMT -4. The time now is 12:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy