Sponsored Content
Top Forums Shell Programming and Scripting While loop read line not working Post 302471346 by mnanavati on Friday 12th of November 2010 02:41:51 PM
Old 11-12-2010
That doesn't work. Now instead of printing the LINE --- 3 times , it prints LINE --- just once.

Also, I am not very clear what you meant by it trying to read line from filename.

I have a surrounding while loop to that above code and that works perfectly file

Code:
while read remotehost
do
 Above mentioned Code
done < "$remotehostlist"

This while loop works fine and provides me the value of remote host.
However the inner while loop does not print the value of $line.

That is the weird part

---------- Post updated at 02:41 PM ---------- Previous update was at 02:27 PM ----------

I changed the code to try this as well.. It still doesnt work!!

Code:
while read  remotehost
do
  ssh -t $2@$remotehost  <<REMOTE

   ls /path/to/dir | while read line
     do
        echo "LINE --- $line"
     done

REMOTE
done < "$remotehostlist"

This code still prints LINE --- 3 times. But does not print value of $line
 

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. UNIX for Dummies Questions & Answers

Alternative for a while read line loop

HELLO all :), I have been trying to use a simple while loop to read a file " templist", line by line and perform an action. See the code below. The reason for not using a while read line loop is the for the use of the if condition that wouldn't work. I would appreciate some ideas as this has... (2 Replies)
Discussion started by: kabs
2 Replies

3. Shell Programming and Scripting

read line in a for loop

Hi All, How can we use read line using the index value of a FOR loop? eg: pt_mstr,pt_status,8 pt_mstr,pt_buyer,8 pt_mstr,pt_sfty_stk,8 pt_mstr,pt_ord_pol,3 pt_mstr,pt_capacity,8 pt_mstr,pt_plan_ord,3 pt_mstr,pt_ord_mult,8 From this file i want to read the line2, 3 and 4 only using a FOR... (3 Replies)
Discussion started by: balajim
3 Replies

4. Shell Programming and Scripting

While read line loop

Hi I'm writing a bash script which will read an input file and look for occurrences of the current user ($USER) executing the script. When i find the occurrence of the username I take that line and append it to a file with a line number and bracket display next to line. The input file has been... (12 Replies)
Discussion started by: BundBash
12 Replies

5. Shell Programming and Scripting

While loop read line Issue

Hi I am using while loop, below, to read lines from a very large file, around 400,000 rows. The script works fine until around line 300k but then starts giving incorrect result. I have tried running the script with a smaller data set and it works fine. I made sure to include the line where... (2 Replies)
Discussion started by: saurabhkumar198
2 Replies

6. Shell Programming and Scripting

Read file using while loop not reading last line

I have written a script to read the file line by line. It is reading and printing the lines. But it is coming out of loop before reading last line. So I am not able to print last line. How do I solve it. (6 Replies)
Discussion started by: dgmm
6 Replies

7. Shell Programming and Scripting

IF awk in a while read line-loop

Hi As a newbe in scripting, i struggle hard with my first script. What i want to do is, bringing data of two files together. file1: .... 05/14/12-04:00:00 41253 4259 5135 5604 5812 5372 05/14/12-04:10:00 53408 5501 6592 7402 7354 6639 05/14/12-04:20:00 58748 6037 7292 8223... (13 Replies)
Discussion started by: IMPe
13 Replies

8. Shell Programming and Scripting

[Solved] While read line and if statement not working

I'm looking for some help in figuring why my little bit of code will not process any entries other then the first one in my list. while read line ;do hostname=${line//\"} a=`ssh user@$hostname uptime;echo $?` if ];then dt=`date` touch... (6 Replies)
Discussion started by: whegra
6 Replies

9. Shell Programming and Scripting

While read line loop

Based on text file: PATH:/media/hdd/Media/Video/title1 FILE:/media/cache/281662-14.jpg PATH:/media/hdd/Media/Video/title2 FILE:/media/cache/281662-15.jpg PATH:/media/hdd/Media/Video/title3 FILE:/media/cache/281662-16.jpg PATH:/media/hdd/Media/Video/title4 FILE:/media/cache/281662-17.jpg... (12 Replies)
Discussion started by: TiedCone
12 Replies

10. Shell Programming and Scripting

While read -a line not working in ksh

while read -a line; this is not working in ksh. what is the equivalent of this in ksh. read: -a: unknown option (2 Replies)
Discussion started by: archana25
2 Replies
dtsdate(1m)															       dtsdate(1m)

NAME
dtsdate - Sets local clock from a remote dtsd server host SYNOPSIS
dtsdate [-q] [-s] [-u] remote_host [nsecs] ARGUMENTS
Queries the difference in time between the local host and the remote host, but does not change the local clock. The returned result (2 if the time would have been reset, 1 if there was an error, and 0 otherwise) can be used by a script to determine what action to take. Causes dtsdate to work silently, without showing the time. Shows the time in UTC, rather than in the current time zone. The name or the IP address of a remote host that has a dtsd server. An integer giving the number of seconds by which the remote and local host times can dif- fer, without the local host's clock being reset. If nsecs is 0, or if it is not specified, it is treated as if it were extremely large, and no resetting occurs. DESCRIPTION
The dtsdate command sets the local clock of a system to be the same as the host remote_host, running a dtsd server. The purpose of dtsdate is to ensure that clock skew is minimized at initial cell configuration or at host instantiation, because it is difficult to start DCE and its components if the skew is too great. Clocks among all DCE components must be within five minutes of each other, to prevent failure of CDS and of security. Some DCE components have even more stringent requirements. For instance, a DFS file server cannot start if its local host differs from other DFS hosts by more than ten seconds. The dtsdate command can be used for adjusting a clock backwards, before DCE is running on a host. Adjusting a clock backwards while DCE is running can cause many difficulties, because security and file system software generally require system time to increase monotonically. NOTES
The remote host must be running as a DTS server. This means that the dtsd on that system must have registered the DTS management inter- face, because dtsdate uses the management call to get the current time from that host. For dtsdate to be able to set the clock, it must run as a privileged user (root). EXIT VALUE
If the -q argument is given, dtsdate returns 2 if the remote time and local time differ by more than nsecs, 1 if there was an error, and 0 otherwise. If the -q argument is not given, dtsdate returns 1 if there was an error, and 0 otherwise. EXAMPLES
With only the host argument: dtsdate remotehost dtsdate prints out the time on the remote host. In this example: dtsdate -s -q remotehost 10 dtsdate does not print out the remote host's time. If the times differ by more than 10 seconds, it returns the value of 1, otherwise 0. In the next example: dtsdate -s remotehost 10 dtsdate sets the clock if it differed from the remote clock by more than 10 seconds. It does this work silently, because of the -s option. The following example shows a shell script that uses the return value of dtsdate: dtsdate -s -q remhost 10 result = $? if [ $result -eq 0 ] ; then echo "Time is within tolerence." elif [ $result -eq 1 ] ; then echo "Could not contact remote host." >&2 else # result = 2 if dtsdate remhost 10; then # it failed! echo "Could not set the clock." >&2 fi fi RELATED INFORMATION
Commands: dtsd(1m) dtsdate(1m)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy