1834225 Members
2347 Online
110066 Solutions
New Discussion

Re: script help.

 
SOLVED
Go to solution
ben_43
Frequent Advisor

script help.

Hi:

In the foll. while loop i am not able to create the /tmp/session file while it is doing so as a seperate command. Please help.

while read sdcole
do
/var/mct/cmd user sdcole |grep -v USERNAME|cut -f3 -d "|" sort |uniq >> /tmp/session_list
done < /tmp/session_list

The above command works fine without the while loop. Iam doing something wrong.Please help.

Thanks
Ben.
6 REPLIES 6
Ted Ellis_2
Honored Contributor

Re: script help.

can you provide the details on what you are trying to accomplish with this script? what is leading to the while loop?

Ted
James R. Ferguson
Acclaimed Contributor
Solution

Re: script help.

Hi Ben:

You are attempting to read the same file to which you write. That isn't going to work.

Regards!

...JRF...
James Murtagh
Honored Contributor

Re: script help.

Hi Ben,

You are using /tmp/session_list as standard output and standard input at the same time, hence why it won't work. You will need to redirect your output to another file.

Regards,

James.
A. Clay Stephenson
Acclaimed Contributor

Re: script help.

You didn't really mean to try to read from a file at the same time that you were writing to it, did you? Consider the case where the file does not exist or is null, the read fails or is false and you never enter your loop. You really need to rethink your approach.
If it ain't broke, I can fix that.
John Meissner
Esteemed Contributor

Re: script help.

why not output to file.1 then mv file.1 to file.2 and read file.2
All paths lead to destiny
Ted Ellis_2
Honored Contributor

Re: script help.

if you are trying to update your file... try and copy the contents of /tmp/session_list to something like /tmp/session_list_orig and use that to feed the while loop... then you will end up with an updated(appended to) /tmp/session_list

Ted