why read line skips some lines...

Dear Guru:

This has got to be a difficult question, as I've worked on it for a good amount of time now & still puzzled...

So here is the simplified logic in my code:

while read LINE
do
#install a pkg with the name extracted from this line
install_pkg name
done < fileWithPkgNamesToBeInstalled

Say, I have 30 of such lines in the file, everything is fine except once it's finished a particular pkg install (which completed successfully with no error), it will skip the next 3 lines in the file, in other words, that 3 pkgs will not get installed.

If I commented out the install function then I can see all the lines including the ones previously being skipped (e.g. "echo $LINE" will not print the 3 lines in the above code):

while read LINE
do
#install a pkg with the name extracted from this line
# install_pkg name
echo $LINE
done < file

I moved that particular line in the file associated with the pkg to any where else, then still with 3 lines skipped, but they moved to a different place just to follow immediately that line.

Can anyone explain why??
Your response would be highly appreciated.

Your looping a list without any controls. My guess is while the first package is being installed the system is busy. When the first package is done installing your script is already on line 4 or 5.

You have two ways to solve this problem. Either write a script that starts the install and has the brains to know when the first install stopped and start the next. (Best way)

or

You can find out how long the largest package takes to install and add 10% wait time to that install time between each of your calls and use the sleep command. (Not the best way)

I wouldn't thread something like this because you might need package 4 installed before package 18.

Perhaps you could invoke install_pkg name as a background process and then 'wait' upon that to complete.

Hi.

I'd guess that install_pkg is reading 3 times from STDIN, which is inherited from the loop, and thus from the file fileWithPkgNamesToBeInstalled.

Is there an option for install_pkg, say -y, that provides automatic answers, or an option that tells it to take input from a file different from STDIN? ... cheers, drl

Guru vino & tomas:-)

What you say seems to make sense to me- that specific pkg takes the longest of all. I made a workaround to make it the last one to be installed- however, I know I have to put into some safety measure in between of any 2 pkgs installations based on what you said.

One thing I have to mention, I do have controls in the loop I omitted earlier just to simplify the example. I validate entries in the line & check returning from the installpkg commond- pkgadd - etc, but there was no error whatsoever.

invoking them in the backgroud may work, but I need to display & save the screen shots of the whole process to a log, as well, some pkgs have interactive prompts.

Perhaps the command pkgadd is asynchronous?

Thanks for the replies, but I had simplified the script a lot! Still simplified, but here's a little more detail of what I'm doing :wink:
(3 pkgs would be missing after the red line)

grep -i '^[^#]*.\.pkg' $pkglist | \
while read LINE ; do
....getting pkgfile & pkgname from the LINE....
pkgadd -a $pkgadmin -d ../packages/$pkgfile $pkgname
if [ $? -ne 0 ]; then
echo "ERROR:......"
fi
done

pkglist includes:
..............
# Tomcat
PSOumTomcat.pkg PSOumTomcat
# AWT
PSOumAWT.pkg PSOumAWT
# Backup restore
PSOumBRServer.pkg PSOumBRServer
PSOumBRClient.pkg PSOumBRClient
......

I agree will drl. The solution is to redirect stdin prior to running the program.

pkgadd -a $pkgadmin -d ../packages/$pkgfile $pkgname < /dev/null

Reading from /dev/null may not be great when it happens, but subsequent iterations of the loop should be ok.

Guru Perderabo & drl:-)

You got the right answer to my question!!:wink:

Thanks again to everyone for your kind responses!!

while this "pkgadd -a $pkgadmin -d ../packages/$pkgfile $pkgname < /dev/null" does solve the original issue- I wonder what if in the "pkgadd $pkgname" it does have to ask question & read from STDIN?
Would that be ignored? Or what if I had to add some functions that read from STDIN...

I know during the "pkgadd" for some of the pkgs, it initially prompted for user inputs, such as passwords, but then, I also know those prompts have been eliminated (by other designers) by setting the pswd etc to default in the pkg scripts as I tried to suppress the interruptions during the installation.

If you know any potential impact of redirecting the STDIN in my code, please let me know.

Thanks!!!