On Sun, May 14, 2023 at 12:20:02AM -0700, Will Mengarini wrote:
> * Tom Reed <t...@dkinbox.com> [23-05/14=Sun 14:21 +0800]:
> > I have a long run shell script [...].  Currently the script
> > is running in front-end in shell.  How can I run it with
> > the backend way? Can I register it as a system service?
> 
> Just run 'myScript&' (the trailing '&' tells the shell to
> run it in the background) if there is no terminal output
> from the running script (terminal output will pause it); if
> there is, enclose the content of the script in redirection of
> standard output and standard error to a log file, or code a
> system service as Jeremy Ardley suggests in a different reply.

Exactly:

  script > /tmp/script.log 2>&1 &

(adjust paths to taste). For good measure, and if your shell
has job control, it will output the job number and PID, like
so:

  [1] 15211

(1 is the job number, 15211 is the PID, actual numbers will
vary). You then issue

  disown %1

(assuming bash here), which lets your shell "forget" about job
number 1 and keep it for messing around once you leave your
shell (in some setups, terminating the shell might terminate
the background jobs, but my memory might be fuzzy).

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature

Reply via email to