How can I execute a command in TrueNAS such that it continues running in the background even when I close the browser shell?

Koloss42

Dabbler
Joined
Aug 21, 2023
Messages
21
I'm looking for a way to run a command in TrueNAS that remains active in the background even after I log out of the browser shell. It should be a method that doesn't necessarily rely on tools like screen or nohup. Is there an alternative solution to achieve this?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
nohup ... & is the standard Unix way. It's a shell builtin, not an external tool. And it's the default in bash, so you need not explicitly write it when using bash as your shell.

I don't get what you mean by "not rely on ... nohup"? Somehow you must tell the shell not to kill the child process when the shell exists, right?
 
Last edited:

Redcoat

MVP
Joined
Feb 18, 2014
Messages
2,925
Could TMUX be useful?
 

Koloss42

Dabbler
Joined
Aug 21, 2023
Messages
21
nohup ... & is the standard Unix way. It's a shell builtin, not an external tool. And it's the default in bash, so you need not explicitly write it when using bash as your shell.

I don't get what you mean by "not rely on ... nohup"? Somehow you must tell the shell not to kill the child process when the shell exists, right?
nohup ... & and than the command or nohup command &
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
nohup <command> &
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Yes but I figured it must be installed through the console book
What's a console book?

tmux is included in every standard TrueNAS installation:

Code:
#TrueNAS CORE:

root@freenas[~]# which tmux
/usr/local/bin/tmux


Code:
# TrueNAS SCALE:

admin@truenas[~]$ which tmux
/usr/bin/tmux
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,553
In general, it's better to pretend like the webshell doesn't exist and just use proper SSH.

The webshell is ok-ish for doing some ad-hoc one-line command, but anything serious (especially things that might break webui or middleware) should be done through SSH.

Oh, and _never_ restart middlewared via a webshell.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
In general, it's better to pretend like the webshell doesn't exist and just use proper SSH.
That does not quite change the "nohup" requirement :wink:
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
In general, it's better to pretend like the webshell doesn't exist and just use proper SSH.
Agreed. So why is it still there?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
@danb35 BÄM! Correctamundo!

If the feature generates more support effort than it saves people effort using it, just ditch it. Seriously. OPNsense and pfSense don't have a shell in the web UI, either. Nobody accuses them of missing that one.

While I am at that ... plugins on CORE? Please just stop advertising them. OK?

Back to the topic of the UI shell - a convenience feature that is not reliable and predictable and does not support copy and paste etc. is not convenient. Remove it for chrissake.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
OPNsense and pfSense don't have a shell in the web UI, either. Nobody accuses them of missing that one.
Though to play the devil's advocate, I can't remember the last time I ssh'd into my OPNsense box--but I ssh into the NAS all the time (mainly to move stuff around with mc). So it might not be directly comparable.

But the thing is, it's entirely possible to do a web shell that doesn't suck; Proxmox has been doing it for years. Heck, even the one in SCALE isn't that bad. But for some reason, iX doesn't seem to be able to put a decent one into CORE.
a convenience feature that is not reliable and predictable and does not support copy and paste etc. is not convenient.
...and now that every major OS includes a ssh client (yes, even Windows), there really isn't any friction there. Just open a terminal (if you don't live with at least one open as I do) and ssh user@ip. Faster than logging into the web UI, and it actually works.
 
Top