Sponsored Content
Full Discussion: nested read
Top Forums Shell Programming and Scripting nested read Post 48402 by TioTony on Friday 5th of March 2004 01:18:00 PM
Old 03-05-2004
nested read

I am hoping someone can help me with this one.

I am writing a ksh script on Solaris. I want to read in host names and some other info from a file, do an "rsh host 'shutdown'" (or any uname for now until I get it working), and then be given some options. The problem is I am using while read LINE do with a nested read like this:


Code:
cat hosts.lst | while read LINE
do
   set ${LINE}
   rsh ${1} 'uname -a'
   DONE=false
   while [[ ${DONE} = false ]]
   do
      echo "[C]heck, [K]ill, [G]o?"
      read ANSWER
      ANSWER=`echo ${ANSWER} | tr -s '[:lower:]' '[:upper:]'`
      echo "ANSWER is ${ANSWER}"
      case ${ANSWER} in
         C ) check_running_processes;;
         K ) kill_running_processes;;
         G ) DONE=true;; #go to next priority
       esac
   done

This isn't the entire script just the section I am having problems with. The problem I cannot get around is when I try to "read ANSWER", $ANSWER is getting the value of $LINE for that iteration. I understand why this is happening but cannot figure out how to get around it.

I have tried putting the read in (), in a separate subroutine, unsetting $LINE, setting $LINE to something else.

Any other ideas?

Thanks,
Tony
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nested while read line loop

Hi, Can anyone please help me: i'm trying to read a file with directory-names , then go to that directory and read another (output) file to perform some tasks per line (second read line in the part of script below). The problem is that after the nested while loop has finished, the first while... (7 Replies)
Discussion started by: Rakker
7 Replies

2. Shell Programming and Scripting

Nested Symlinks?

Please don't laugh or call me a fool... I'm trying to set up a script that will go through my Music File directory and generate a set of symbolic links in a directory called "What's New". Within that directory there will be a "30 Days", "3 Months", "6 Months" and "A Year" directories. Within... (0 Replies)
Discussion started by: deckard
0 Replies

3. Shell Programming and Scripting

while read loop w/ a nested if statement - doesn't treat each entry individually

Hi - Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert. The list file (ldaplist) would look like - *********** o=company a o=company b *********** **... (7 Replies)
Discussion started by: littlefrog
7 Replies

4. Shell Programming and Scripting

nested for loops

I need help getting over this bump on how nested for loops work in shell. Say i was comparing files in a directory in any other language my for loop would look like so for(int i=0;to then end; i++) for(int y = i+1; to the end; y++) I can't seem to understand how i can translate that... (5 Replies)
Discussion started by: taiL
5 Replies

5. UNIX for Dummies Questions & Answers

Nested If statement within Do / Done

Hi all! I'm really hoping you can help me out here; now i have searched and searched and have at least worked out that you can't have a nested if statement with a 'done' in it (as i have) as you're killing the parent before the child. So here's what i have, and here's hoping someone can help... (2 Replies)
Discussion started by: dalgibbard
2 Replies

6. UNIX for Dummies Questions & Answers

Faster than nested while read loops?

Hi experts, I just want to know if there is a better solution to my nested while read loops below: while read line; do while read line2; do while read line3; do echo "$line $line2 $line3" done < file3.txt done < file2.txt done < file1.txt >... (4 Replies)
Discussion started by: chstr_14
4 Replies

7. Shell Programming and Scripting

Optimize the nested IF

Hi, I have to assign a value for a varaiable based on a Input. I have written the below code: if then nf=65 elif then nf=46 elif then nf=164 elif then nf=545 elif then nf=56 elif then (3 Replies)
Discussion started by: machomaddy
3 Replies

8. Shell Programming and Scripting

Nested ifs

hi I keep getting an error with this nested if statement and am getting the error unexpected end of file, can anyone help me as to why this wont execute? #!/bin/bash #script to check wether the -i -v statements run correctly removeFile () { mv $1 $HOME/deleted }... (3 Replies)
Discussion started by: somersetdan
3 Replies

9. Shell Programming and Scripting

Nested if else

Hi, i m trying to create script which logic is like below. if ; then x=`cat /tmp/testoutput.log | grep STOP | wc -l` y=`cat /tmp/testoutput.log | grep RUN | wc -l` if ; then echo "process stop" if ; then echo "process running " else echo "file not found" fi ----------------... (2 Replies)
Discussion started by: tapia
2 Replies

10. UNIX for Dummies Questions & Answers

[Solved] Nested If

I am having a problem with a nested if. I am sure I am overlooking something. I check for the existence of $Pidfl3 and it exists, o this condition I then want to check for the existence of a next file and remove it. The first if is executed, but on the second if I get test: argument expected. My... (4 Replies)
Discussion started by: Charles Swart
4 Replies
UPSCLI_GET(3)							    NUT Manual							     UPSCLI_GET(3)

NAME
upscli_get - retrieve data from a UPS SYNOPSIS
#include <upsclient.h> int upscli_get(UPSCONN_t *ups, int numq, const char **query, int *numa, char ***answer) DESCRIPTION
The upscli_get() function takes the pointer ups to a UPSCONN_t state structure, and the pointer query to an array of numq query elements. It builds a properly-formatted request from those elements and transmits it to upsd(8). Upon success, the response will be split into separate components. A pointer to those components will be returned in answer. The number of usable answer components will be returned in numa. USES
This function implements the "GET" command in the protocol. As a result, you can use it to request many different things from the server. Some examples are: o GET NUMLOGINS <ups> o GET UPSDESC <ups> o GET VAR <ups> <var> o GET TYPE <ups> <var> o GET DESC <ups> <var> o GET CMDDESC <ups> <cmd> QUERY FORMATTING
To generate a request for GET NUMLOGINS su700, you would populate query and numq as follows: int numq; const char *query[2]; query[0] = "NUMLOGINS"; query[1] = "su700"; numq = 2; All escaping of special characters and quoting of elements with spaces is handled for you inside this function. ANSWER FORMATTING
The raw response from upsd to the above query would be NUMLOGINS su700 1. Since this is split up for you, the values work out like this: numa = 3; answer[0] = "NUMLOGINS" answer[1] = "su700" answer[2] = "1" Notice that the value which you seek typically starts at answer[numq]. ERROR CHECKING
This function will check your query against the response from upsd(8). For example, if you send "VAR" "su700" "ups.status", it will expect to see those at the beginning of the response. If the results from upsd do not pass this case-insensitive test against your request, this function will return an error. When this happens, upscli_upserror(3) will return UPSCLI_ERR_PROTOCOL. ANSWER ARRAY LIFETIME
The pointers contained within the answer array are only valid until the next call to a upsclient function which references them. If you need to use data from multiple calls, you must copy it somewhere else first. The answer array and its elements may change locations, so you must not rely on previous addresses. You must only use the addresses which were returned by the most recent call. You also must not attempt to use more than numa elements in answer. Such behavior is undefined, and may yield bogus data or a crash. The array will be deleted after calling upscli_disconnect(3). Any access after that point is also undefined. RETURN VALUE
The upscli_get() function returns 0 on success, or -1 if an error occurs. SEE ALSO
upscli_list_start(3), upscli_list_next(3), upscli_strerror(3), upscli_upserror(3) Network UPS Tools 05/22/2012 UPSCLI_GET(3)
All times are GMT -4. The time now is 04:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy