Quantcast
Channel: Start a background process from a script and manage it when the script ends - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

Start a background process from a script and manage it when the script ends

$
0
0

I'd like to run and configure a process similarly to a daemon from a script.
My shell is zsh emulated under Cygwin and the daemon is SFK, a basic FTP server.

For what matters here, the script startserv.sh can be drafted as follows:

#!/bin/shread -s -p "Enter Password: " pwuser=testusershare=/fsharecmd="sfk ftpserv -user=$user -pw=$pw -usedir $share=$share"$cmd &

After running the script startserv.sh, it stops (ends?) without showing any prompt, then:

  • CTRL+C ends both the script and the background job process;

  • Hitting Enter the script ends the process remains in the background.

Anyway I can see it only via ps and not jobs, so, when I want to close the process, I have to send a brutal kill -9 signal, which is something I'd like to avoid in favour of CTRL+C.

An alternative would be running the whole script in background. 'Would be', but the read command is unable get the user input if the script is run as startserv.sh &.

Note that I need an ephemeral server, not a true daemon: that is, I want the server process to run in the background, after the script ends, to perform simple interactive shell tasks (with a virtual machine guest), but I don't need the process to survive the shell; therefore nohup seems not appropriate.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>