0

I used to have a script (way back when) that allowed me to execute ANYTHING in terminal and would magically disown and run in the background while dumping any output to null. It may have even nohup'd...I don't recall. I had it located in /usr/local/bin or /usr/bin/ and it was named 'ds' (I know that the name has nothing to do with it, but I figure perhaps some of you may have done the same thing as I did back in the day).

Basically, to execute a command completely in the background and not tying up a terminal window, I would simply type in:

ds command

or

ds sudo command

I don't recall where I found it nor whether I created it myself. It was pretty ingenious, so I am guessing I found it elsewhere. :)

Can anyone help in creating such a script again?

TIA!

0

I'm not sure what you had set up before, but you can output stderr and stdout to /dev/null, and disown the process:

command > /dev/null 2>&1 & disown
$ tail -f /var/log/messages > /dev/null 2>&1 & disown
[1] 12345
$

Do not confuse & and && here. & runs the command in the background, while disown 'de-couples' the background from the terminal process a bit. You can set up a BASH script, function, or alias to wrap your commands in something similar.

  • Yea. I use && in a lot of my aliases to string together a large group of commands. i.e. updates + upgrades + dist-upgrades + autoremoves + autocleans, etc. Any idea how I would script it so that it would take my command and modify it? – Falcor Apr 29 '19 at 6:38
  • Have you tried to use any of the special variables ($*) in a function? – earthmeLon Apr 29 '19 at 7:16
0

My goodness! I found the exact thing I was looking for on one of my other *nix machines and will copy it over to the one that really needs it. Located at "/usr/local/bin/ds"

Here is a copy of the script in case any one would like it:

#!/bin/sh

if test -t 1; then
  exec 1>/dev/null
fi

if test -t 2; then
  exec 2>/dev/null
fi

"$@" &

Now that I look at it, I am not entirely sure that this disowns the process as it would appear to simply execute the command as a background process. Thoughts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.