Bash:Redirection Halts
I have a command e.g. ls-l > 开发者_StackOverflowfile.txt When there is insufficient space on my drive, the above command just stalls waiting for something to happen. Does anyone know about a code that I could write enabling me to display a message about the lack of space on my drive? E.g. could I use IPC or do you have any other ideas? Thanks in advance.
you can use df
command to determine amount of free space on drive, and do not start your processing if there's less than 5M of free space for example.
Or you can check free space amount from your inner program and write warning message to the STDERR.
Pipe command output through another program which will intercept write errors (e.g. ENOSPC
), print diagnostics and fail if nothing else can be done.
This program can be as simple as cat
:
foobar | cat > file.txt
cat
will report error and die, and foobar
will receive SIGPIPE
with default action to die as well.
精彩评论