|
|||||||
| 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
|
|||
|
|||
|
Redirecting stdout problem
I have a simple bash script that prints sth every 5 seconds. What I do is the following. I redirect the output of the script to a file, tail the file and see that it works and then from another console I delete the file where the output is redirected to. Even though I have deleted the file, the tail still works. Stoping the tail and starting it again of course fails because the file is not found.
My question is whether this is normal and does the output go "somewhere" after deleting the file where it is supposed to be redirected. Best, Iliya |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
The file still exists until everything with it open, closes it or quits. Try truncating it, i.e. overwriting it with nothing, instead of deleting it. Having it open can't prevent that from happening, and tail -f is usually smart enough to seek back to the beginning. Code:
: > filename |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Yes, the open file descriptors that refer to the deleted file remain (there will be an unnamed file). Consider the following example (this is on Linux): Code:
zsh-4.3.17[t]% zsh -c 'while :; do sleep 3;date ; done > outfile'& [1] 1470 zsh-4.3.17[t]% ls -l /proc/1470/fd total 0 lrwx------ 1 drado drado 64 Jun 20 23:08 0 -> /dev/pts/2 l-wx------ 1 drado drado 64 Jun 20 23:08 1 -> /home/drado/t/outfile lrwx------ 1 drado drado 64 Jun 20 23:08 10 -> /dev/pts/2 lr-x------ 1 drado drado 64 Jun 20 23:08 11 -> /dev/null lrwx------ 1 drado drado 64 Jun 20 23:08 12 -> /dev/pts/2 lrwx------ 1 drado drado 64 Jun 20 23:08 2 -> /dev/pts/2 zsh-4.3.17[t]% tail -f /home/drado/t/outfile Wed Jun 20 23:08:08 CEST 2012 Wed Jun 20 23:08:11 CEST 2012 Wed Jun 20 23:08:14 CEST 2012 Wed Jun 20 23:08:17 CEST 2012 Wed Jun 20 23:08:20 CEST 2012 Wed Jun 20 23:08:23 CEST 2012 ^C zsh-4.3.17[t]% rm /home/drado/t/outfile zsh-4.3.17[t]% tail -f /home/drado/t/outfile tail: cannot open `/home/drado/t/outfile' for reading: No such file or directory zsh-4.3.17[t]% tail -f /proc/1470/fd/1 Wed Jun 20 23:08:14 CEST 2012 Wed Jun 20 23:08:17 CEST 2012 Wed Jun 20 23:08:20 CEST 2012 Wed Jun 20 23:08:23 CEST 2012 Wed Jun 20 23:08:26 CEST 2012 Wed Jun 20 23:08:29 CEST 2012 Wed Jun 20 23:08:32 CEST 2012 Wed Jun 20 23:08:35 CEST 2012 Wed Jun 20 23:08:39 CEST 2012 Wed Jun 20 23:08:42 CEST 2012 Wed Jun 20 23:08:45 CEST 2012 ^C zsh-4.3.17[t]% lsof -p1470|fgrep outf zsh 1470 drado 1w REG 252,0 630 261137 /home/drado/t/outfile (deleted) zsh-4.3.17[t]% kill -9 %1 zsh-4.3.17[t]% [1] + killed zsh -c 'while :; do sleep 3;date ; done > outfile' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| redirecting to stdout in betwen command | phoenix_nebula | Shell Programming and Scripting | 4 | 03-16-2010 01:09 AM |
| Redirecting several outputs to /dev/stdout | aplaydoc | UNIX for Dummies Questions & Answers | 1 | 03-06-2009 10:42 PM |
| Redirecting part of output to stdout | Legend986 | Shell Programming and Scripting | 2 | 10-17-2008 03:20 PM |
| implicitly redirecting stdout to a file | ALTRUNVRSOFLN | Shell Programming and Scripting | 1 | 09-23-2008 03:42 PM |
| redirecting STDOUT & STDERR | jshinaman | Shell Programming and Scripting | 9 | 06-22-2007 12:04 AM |
|
|