Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Generated or received a file descriptor number that is not valid

 
Highlighted
jfr1
Visitor

Generated or received a file descriptor number that is not valid

Hi there.

I'm running a shell script that is calling another one.

So it looks like this:

 

runer.sh

exec 4<&0
while read Filer User Password Sysdba; do
case $Filer in
*.sh)
exec 5<&0
exec 0<&4
.$Filer
if test $? -ne 0;
then echo ERROR: .$Filer encountered an error ` 2>&1 | tee -a $LOG_DIRECTORY
echo 2>&1 | tee -a $LOG_DIRECTORY
fi;
exec 0<&5;;
;;
esac
done < `basename $list_file`;


FileinFiler.sh
echo 'Do you really wish to remove the user (y/n)?' 2>&1 | tee -a $LOG_DIRECTORY
exec 5<&0
exec 0<&4
read continue
exec 0<&5

 

So line 3 in FileinFiler.sh (exec 0<&4) is causing the above error.

 

When I run this in Linux with LSOF I see that the file descriptor is recognized.

So I guees that in HP-UX, the filedescriptor 4 has been lost for the switch of content when calling the second shell (I do not know how to install LSFOF in HP-UX...looking for that info now).

 

So my question is: how do I fix this one? I think the intent here is to get the value of the answer in the continue variable and write it to a file.

 

Thanks for any help.

5 REPLIES 5
Highlighted
Dennis Handly
Acclaimed Contributor

Re: Generated or received a file descriptor number that is not valid

>.$Filer

 

Is there a space after the period?

 

>echo ERROR: .$Filer encountered an error ` 2>&1 | tee -a $LOG_DIRECTORY
>echo 2>&1 | tee -a $LOG_DIRECTORY

 

That (`) is unbalanced.  Also you don't need to use "2>&1" here.  And you might as well combine the two echoes:

   echo "ERROR: .$Filer encountered an error\n" | tee -a $LOG_DIRECTORY

 

>echo 'Do you really wish to remove the user (y/n)?' 2>&1 | tee -a $LOG_DIRECTORY
exec 5<&0
exec 0<&4
read continue

Why bother with this exec fiddling if this is already done in runer.sh before FileinFiler.sh is called?

 

>I guess that in HP-UX, the filedescriptor 4 has been lost for the switch of content when calling the second shell (I do not know how to install lsof in HP-UX.).

 

You want tusc instead to trace the system calls.

Highlighted
jfr1
Visitor

Re: Generated or received a file descriptor number that is not valid

Yes the unbalanced ' was a copy and paste mistake.

No space before the period.

 

I think the intent was to grab th response and add it to the log file somehow.

 

Your suggestions are fine, but they do not cause the error that I'm experiencing.

 

Not sure what tusc is.

 

 

Highlighted
Dennis Handly
Acclaimed Contributor

Re: Generated or received a file descriptor number that is not valid

>No space before the period.

 

I was asking about after.  If you source that script, it doesn't have that FD error.

 

>Not sure what tusc is.

 

As I said, this is the tool you need.  It traces system calls.

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-8.1/

 

tusc shows that a real shell doing I/O redirection with exec command, calls: fcntl(FD, F_SETFD, FD_CLOEXEC)

This doesn't happen if you source the script.

But since the file you source redoes the redirection, FD 5 is destroyed in the first script.

Highlighted
jfr1
Visitor

Re: Generated or received a file descriptor number that is not valid

Thanks for your quick answers...but I do not think I follow you with the source thing.

My experience with HP-UX is a total of about 2 days.

 

Highlighted
Dennis Handly
Acclaimed Contributor

Re: Generated or received a file descriptor number that is not valid

>but I do not think I follow you with the source thing.

 

Do you have a space after that period?  That's called sourcing in a real shell.

When you source a script, you don't do an exec, so the redirected files remain open.

 

And then you'll need to remove the exec(s) in the FileinFiler.sh.