linux - how to backup stdout of running shell script -
here short example of problem
short script writes every 10 seconds test stdout
> cat write.sh #!/bin/sh while [ 1 ];do echo test sleep 10 done
and here how execute it, redirect stdout file named output.txt
./write.sh > output.txt
now, script should run "forever", meantime fills output.txt
we looking way backup output.txt
without restart script. moreover, looking implicit solution, script won't aware file backed up.
of course once remove file (e.g. compress it) process (script) lose track of file , stop writing. if backup file (compress) , return file using touch
script no long able reattach file.
for example:
mv test_file.txt test_file111.txt
rm test_file111.txt
> lsof | grep write write.sh 2644 ronnyr 1w reg 253,1 36 106059124 /home/ronnyr/test_file111.txt (deleted)
> touch test_file111.txt write.sh 2644 ronnyr 1w reg 253,1 36 106059124 /home/ronnyr/test_file111.txt (deleted)
if want alter or truncate output file use >>
this:
./write.sh >> output.txt # take backup cp -p output.txt /path/backup/ # truncate stdout file > output.txt
due use of >>
(append) ./write.sh
keep writing output @ end of file , remain unaffected when truncate output file.
Comments
Post a Comment