How to start and keep a process running even after closing the terminal?

Hello,

I need to keep a process running in my terminal connected to my QNAP TS-131P NAS. Problem is: if I close my terminal window, the process obviously stops. I tried all methods suggested in this message, but none of them work because the utilities used are not installed on the NAS (e.g. nohup, screen, tmux are all missing)…

So, I’m in a dead-end…How can I start and keep a process running even after closing the terminal in my QNAP NAS?

Thank you.

Is nohup not in here?

https://www.myqnap.org/product/entware-std/

Are you sure? I’ve abandoned SSH sessions (not logged out, just closed the window) and I thought the process continued. I could be wrong, I know this is the case for a different brand NAS that I also have.

Is this a regular task that you run? Could you make it part of the system crontab instead of running it manually?
Have you also tried running it in the background and disowning it?

https://www.reddit.com/r/linuxquestions/comments/ypkcj6/terminal_how_do_i_run_a_command_send_it_to_the/

Could the job be run in a container?

GNU screen is included with QTS. Use it. :nerd_face:

Is nohup not in here?

Thank you. I installed the Entware-Std qpkg, and typed nohup but it wasn’t included. However, tmux is included, and I think this will do the trick :slightly_smiling_face:

Thank you. As I said in my original message, it is not included on my QNAP NAS. When I type screen, I get a “Command not found” error message. However, I managed to install tmux and it should solve my problem.

Yes, it must be run in the background 24/7. It’s a script that polls a server every 15 minutes to keep a connection alive. It’s a bash script that keeps alive the port forwarding functionality of a VPN server, it was provided by a VPN server company.

No, because I need the initial output of the bash script, as it returns the port number given by the remote VPN server. The cron tab doesn’t provide the output of the script, it just runs it. Additionally, every time this script is run, it returns a new port number, and I would have to change port number in my endpoint application accordingly every time (which wouldn’t be manageable).

I haven’t but I’ve bookmarked this page you gave. If needed, I’ll look into it. I was able to install Entware-Std, which ships with tmux. I’m currently trying it, and it seems it’s finally working. Thank you.

Thank you. It could, but I think I won’t have to, as I managed to install Entware-Std (the manual qpkg installation). It has a tool called tmux, and it seems to be working fine running my script even after closing the terminal :wink:

2 Likes

Good for you! :smiley:

1 Like

As I said, it’s included with QTS.

Are you logged-in through SSH as the original admin user, or a user you’ve created? If you’re using a secondary account, you’ll need to prefix many commands with sudo.

If you configured the script correct it can provide an output. I am running several scripts per cron, writing an outout in a log file and/or sending the output by mail.

So I am always aware if something changes or does not act as expected.

Regards

1 Like

I’m logged in as the original admin user.

Thank you. I’ll keep this option, just in case. It might come in handy.

You can use the following form with same result then nohup:

bash /share/homes/admin/bin/SCRIPT.sh < /dev/null > /dev/null 2>&1 &

“< /dev/null” disconnect the console for input from the bash script
”> /dev/null” disconnect the console for output from the bash script
”2>&1” disconnect the console for error mesages from the bash script
”&” puts the script in the background.
That’s what nohup basically does.

I tested this on a TS-851 QTS 5.2.8.3350 Build 20251216 I own.

Hi and welcome to the forum. :slight_smile:

nohup and & perform different functions. There are times when they’re even used together.

Backgrounding a process does not ensure it won’t be killed when the user disconnects their terminal session.

But it did work.

It can work. It’s unreliable though. :nerd_face:

Hi, I had great expectations with tmux, but after a day, it would stop working. I installed nohup last week, and to date, it hasn’t stopped working. This is how I did:

  • Install Entware_1.03std.qpkg
  • Install nohup using the package manager: opkg install coreutils-nohup
  • Run the script of your choice, e.g. nohup ./port_forwarding.sh &
  • If you need to view the output of your script, run: vi nohup.out

Then, you can log out of your terminal. Your script should still be executing.

‘nohup’ is absolutely unnecessary! I did it like this:

./$script.sh &
sleep 2
disown -h “%$ID

where ID is an integer from 1 to x, so
`%1` for the first script started,
`%2` for the second script started
and so on.