|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
bash: closing file descriptors from a process
Below is a test script to illustrate a problem from a larger script I am writing. Code:
$ cat /tmp/loggingtest #!/bin/bash lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") sync & wait lvremove -f vg00/var-data-snapshot 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") When I run this I receive the following output in /var/log/syslog. Specifically I cannot understand where the "File descriptor 62 left open" and "File descriptor 63 left open" errors are coming from. Also the script hangs until I press enter. Code:
Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 62 left open Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 63 left open Sep 12 11:57:39 debvelopment loggingtest.info: Logical volume "var-data-snapshot" created Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 62 left open Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 63 left open Sep 12 11:57:39 debvelopment loggingtest.info: Logical volume "var-data-snapshot" successfully removed I have done research but I am finding it difficult to understand whether these errors are related to lvm, syslog or something I am doing wrong in bash? let alone how to close the file descriptors properly. ---------- Post updated at 06:12 PM ---------- Previous update was at 12:01 PM ---------- I can now prevent the errors and know that the descriptors are from "logger" but I still do not understand it. I added "62>&- 63>&-" to the end of each command and this resolves the errors e.g. Code:
#!/bin/bash lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") 62>&- 63>&- sync & wait lvremove -f vg00/var-data-snapshot 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") 62>&- 63>&- But what if the file descriptors where to change? How can I identify the relevant file descriptors and then close them? Do I need to even be concerned as they appear to close anyway? Thanks |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
you just have to close them then: Code:
#!/bin/bash
{
exec 62>&-
exec 63>&-
lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data
} 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info")
sync &
wait
{
exec 62>&-
exec 63>&-
lvremove -f vg00/var-data-snapshot
} 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info")---------- Post updated at 04:19 PM ---------- Previous update was at 04:16 PM ---------- Thanks to this thread I now know why I have some fds left open even if I close a duplicate fd. |
| Sponsored Links | ||
|
![]() |
| Tags |
| bash, file descriptors, lvm, syslog |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bash script to process file without regard for case | manouche | Shell Programming and Scripting | 1 | 04-06-2010 07:34 PM |
| starting a bash session as child process to another bash session from a process | alirezan | Shell Programming and Scripting | 5 | 03-13-2009 09:03 PM |
| Closing ssh when process run on remote | tipi | UNIX for Dummies Questions & Answers | 1 | 09-03-2008 06:46 PM |
| how to run a process after closing the terminal | lakshmananindia | UNIX for Advanced & Expert Users | 3 | 09-03-2007 11:05 AM |
| Max No of Open File Descriptors in a process | lakshmankumar12 | UNIX for Advanced & Expert Users | 2 | 12-29-2004 10:54 PM |
|
|