This is about as bizarre as anything I've ever seen.
I have a little test script I've been working with. When I redirect stdout to a file, no file. Make a copy of the script to another name. Execute it and redirect stdout, and I get the file.
Starting with the file listing, the file eds_scp_test is the file in question:
Just execute the file, and everything is as expected:
Execute it again, but redirect stdout to a log file (errout will still go to display)
But where's the log file?
Now, make an exact copy of the subject script:
And test it
And this time we get the expected log file:
Sign me -- Perplexed.
The first time you run it, you get this error, because eds_scp_test.log does not exist:
The second time, though, you do not get this error because the script actually succeeds in deleting it -- it's the very first thing it does.
Once you delete it, it naturally no longer exists. (Since it's busy, it will remain on disk -- but not in the folder -- until the script finishes. Once nothing is keeping it open, it will vanish for good.)
Last edited by Corona688; 05-28-2015 at 01:50 PM..
Hmm. Another case of getting so close to the code that one doesn't see it any more. In this case, the deleting of the log file within the script was a vestige of the larger script from which this test piece came. And that script was doing its own logging, rather than redirecting the output as a whole, as in my test. One thing I still don't understand though. Given that I was redirecting stdout of the script as a whole (myscript > myscript.log) even with a command inside the script deleting that same file, would not the next command that generates stdout in the script re-create the specified file?
Calling the write() system call does not create a file. Only open() does that, and the only time your program does that is when you do > filename.
In UNIX, where a file is and what its contents are, are separate questions. What really keeps a file's contents is its inode. If you hardlink a file into two different folders, they will share the same inode.
So when you delete a file which happens to be open, it will delete its directory listing, but the file itself -- its inode -- will still exist until you close it. (or the program holding it quits.) After that, it will be freed completely from disk.
This is a common trap new administrators fall into, incidentally. When they find a huge logfile filling up the disk, they delete it -- which makes things worse because the file remains open, but can't be shrunk from the console anymore. Whatever service is keeping it open would have to be stopped or convinced to close it before the disk space becomes free.
I have a problem when i try to create a log file from a daemon process using shell scripting in ubuntu 12. Ultimatly what i want to achieve is run a java/jar file from a script. After scourging the internet i found several solutions to do this, the one i choose is to create a startup script that... (4 Replies)
EDIT: Nevermind, figured it out! Forgot to put backslashes in my perl script to not process literals!
Hi everyone. I am trying to have this command pass silently. (no output)
chsh -s /bin/sh news
Currently it outputs.
I've tried....
&> /dev/null
1> /dev/null
2>&1 /dev/null
1>&2... (1 Reply)
I have a ksh script (dtksh Version M-12/28/93d on Solaris 10) that is run daily by cron and sometime hangs forever. I need to detect if there is an old copy hung before I start the new run, and if so send an email and exit the script. Here is part of the code:
#!/usr/dt/bin/dtksh... (4 Replies)
Hi,
I would like to avoid re-directing line by line to a file.
What is the best way to re-direct STDOUT to a file in a subshell?
Thanks in advance.
Cheers
Vj (1 Reply)
Hi,
i know how to
a) redirect stdout and stderr to one file,
b) and write to two files concurrently with same output using tee command
Now, i want to do both the above together.
I have a script and it should write both stdout and stderr in one file and also write the same content to... (8 Replies)
In my program, I am using library provided by other. In the library, the cout/cerr is redirected to a file (the file path is known).
After I call some methods in the library, I get one side-effect --> The cout/cerr in my own program is also directed to the file.
So how can I to redirect... (5 Replies)
Hi friends
I am facing one problem while redirecting the out of the stderr and stdout to a file
let example my problem with a simple example
I have a file (say test.sh)in which i run 2 command in the background
ps -ef &
ls &
and now i am run this file and redirect the output to a file... (8 Replies)
Hi all hope you can help as I am going MAD!!! :eek:
The below is in a shell script but the redirection in the sed line does not work and outputs to the screen and the $fname_2 does note get created ?????
Can any one help ??
#!/bin/ksh
cd /app/
for fname in `ls -1 X*`
do
sed 1d $fname... (3 Replies)
How can I redirect and append stdout and stderr to a file when using cron? Here is my crontab file:
*/5 * * * * /dir/php /dir/process_fns.php >>& /dir/dump.txt
Cron gives me an 'unexpected character found in line' when trying to add my crontab file.
Regards,
Zach Curtis
POPULUS (8 Replies)