Note: I've read the other question, but I need it differently.
I'm working on my NAS, which also works as a storing device for my PVR. Now I want to change my shell prompt on the NAS whenever the PVR is writing a broadcast to it (consider it a "don't do anything long-lasting while a broadcast is being recorded"-warning). My first idea was to prefix the prompt with a red
As pointed out in the other question I can use
lsof for this:
# lsof /broadcast/storage/path/broadcast.ts; echo $? <output of lsof> 0 # lsof /broadcast/storage/path/doesnt-exist.ts; echo $? 1 #
lsof doesn't seem to work for me if I use
# lsof /broadcast/storage/path/*; echo $? <output of lsof> 1 #
The logic seems to be that it returns 1 when it finds a file that is not in use. However, for me it should return 0 when at least one file is in use.
I know that I can loop over the files and stop when the first file returns 0, but since I want to have this in the prompt I don't know how to make this a one-liner.
Thanks to tink I reworked my idea and my prompt now looks like this (note that I had to make the wildcard work as
lsof /.../* would be globbed into PS1 already):
export PS1='`find /broacast/storage/path/ -name "*.sc" -print0 | \ xargs -0 lsof | \ grep -q COMMAND && echo -e "\033[0;31m[REC]-\033[0;37m"`\u@\h:\w\$ '