I am facing a strange problem with my code, I have a script which does housekeeping of oracle DB generated files. We have multiple DB's running with different OS users, so we are executing the script as root user, which will generate a dynamic script for each DB, and it will switch to the DB owner (OS user) and execute the dynamically generated cleanup script.
This script is working fine in our HP-UX B.11.31 & Linux servers but fails to execute as expected on HP-UX B.11.11 servers.
When i investigated it further, i found that the script is breaking out of while loop after processing first element in the loop.
Flow of the Script is as follows:
1) List out the DB's running on the server along with OS account under which it is running.
2) Generate a dynamic script for oracle realated cleanup activity.
3) Get into a while loop with list of DB's running
4) switching to DB owner (os user) and execute the dynamic script generated in step 2.
eg: su - abcora -c /tmp/runtime_DB1.ksh
5)repeat step 4 for all DB's running on the server and then exit out of the while loop
In case of our HP-UX B.11.11 system, after first iteration of switching user, it comes out of the loop.
There are no error messages displayed on the screen or captured in the log file, but script is not executing as expected.
Can you guys please help me in resolving this issue. If you need more info please let me know.
su - abcora processes the shell start scripts of user abcora. (You did not say which login shell.)
There is certainly something that reads from stdin, that does "read away" the loop's input.
Work-arounds:
redirect the stdin of suspicious commands
su - abcora -c /tmp/runtime_DB1.ksh </dev/null
harden the loop with the following file descriptor magic
while read line <&3;do
... # stdin will read from &1 - while the loop reads from &3
done 3< list.txt
It's not a question of "accurate", the computer does exactly what you tell it to with 100% precision.
The point is avoiding file descriptor #1, because something inside your loop "eats" it, ending the loop early.
while read LINE
do
cat # This also reads from 'inputfile', so this loop will only run once!
done < inputfile
while read sid <&3 #
do
cat # It doesn't read from 'inputfile' since that's not standard input here.
done 3< inputfile