Run Bash Script in a Separated Process (Dettached from Ssh/Putty) [Duplicate]

I'm accessing Ubuntu Server from a putty terminal and then I run this test.sh script from that terminal:

$ bash test.sh & (note the &)

#!/bin/bash
while true
do

    node myscript.js

    wait $!
    sleep 5

done

Which is supposed to keep that node script running "forever". The issue is that when I close the SSH session/remote terminal (Putty) the script is also terminated.

How do I keep that script running after closing that SSH session?

2

Use crontab -e and add your file there. Search how to use crontab to determine how to setup the correct timing. crontab is used to run scripts every X minutes/hours/days or even on specific dates (every 5th day of the month at 7 pm). It will run the script in the background for you.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest