Search code examples
linuxbashsleepbackground-process

Run "dummy" background command with specific text


I'm looking for a bash command I can run in the background that will sleep for a bit (60 seconds), and the command will contain a specific text string I can grep out of a ps command.

I can't release a "dummy" script I'm afraid, so it needs to be a one line command.

I tried

echo "textneeded">/dev/null && sleep 60 &

But of course the only text I can grep for is the sleep, as the echo is over in a flash.

(The reasoning for this is it's for putting another script in "test" mode so it doesn't create child processes, but other functionality that ensures there are none of these processes running will still find something, and therefore wait. The other functionality isn't in a bash script.)


Solution

  • I had to do this to test a process killing script. You can use perl to set the process name.

    perl -e '$0="textneeded"; sleep 60' &
    

    Original props goes to this guy