Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 REC.

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
#

However, 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.

EDIT:
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\$ '
share|improve this question
up vote 2 down vote accepted

At the risk of stating the obvious, why don't you just:

lsof /broacast/storage/path/* | grep -q broadcast/storage/path ; echo $?
share|improve this answer
    
That takes way too long to be used in a prompt. – sjngm Mar 30 '13 at 19:19
    
I see. How about a double-whammy? I edited the original answer to match what I suggested. – tink Mar 30 '13 at 19:24
    
Oh, good idea. See my edit in the question. – sjngm Mar 30 '13 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .