Substitute an already running command

c=$(pgrep <cmd>) && <new_cmd> && kill $c
eg: Already running cmd sleep 120 Substitution cmd c=$(pgrep sleep) && sleep 5 && kill $c

By: totti
2011-09-14 19:58:30

These Might Interest You

  • Useful when you have only one terminal session e.g. ssh. and want to queue up another command after the currently running has finished(in case if you forget to run that command). Originally used as ; python-updater when running emerge. When I have noticed that a package failed due to that command not run.

    a command is running... <^z> fg; scheduled_command
    denysonique · 2010-07-28 19:25:19 0
  • Searches your $PATH for whatever you substitute for bash, though not sure if this will work if you substitute a different shell for bash! Show Sample Output

    find ${PATH//:/ } -name \*bash\*
    DoNotRememberMe · 2010-03-16 04:26:27 1
  • You're running a script, command, whatever.. You don't expect it to take long, now 5pm has rolled around and you're ready to go home... Wait, it's still running... You forgot to nohup it before running it... Suspend it, send it to the background, then disown it... The ouput wont go anywhere, but at least the command will still run... Show Sample Output

    ^Z $bg $disown
    fall0ut · 2009-03-17 21:52:52 13
  • The dates in the output are Start Date, End Date, Days Remaining in warranty, respectively. This will only work if you are running it on a dell machine. You can substitute the dmidecode command with a service tag if you are not using a dell. Also, you have to either allow your user to run sudo dmidecode with no password or run this command as root. Show Sample Output

    curl -Ls "$(dmidecode -s system-serial-number)"|egrep -i '>Your Warranty<|>Product Support for'|html2text -style pretty|egrep -v 'Request|View'|perl -pane 's/^(\s+|\})//g;'
    din7 · 2011-02-18 22:29:05 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: