I have this bash setup configured to run in tandem with a Wifi manager, which provides events like HOTSPOT, CONNECTING, CONNECTED
I want to run scripts based on events and return immediately, not wait for the scripts to finish, because the Wifi manager would temporarily pause until scripts are run.
#!/bin/bash Logfile="/home/arjun/Desktop/bash/logfile.txt" echo "Started" >> $Logfile if [ "$1" == "CONNECTING" ]; then echo "args CONNECTING" >> $Logfile elif [ "$1" == "HOTSPOT" ]; then echo "args HOTSPOT" >> $Logfile kill $(< my_sinatra_server.pid) elif [ "$1" == "CONNECTED" ]; then echo "args CONNECTED" >> $Logfile nohup ~/Desktop/ruby/sinatra/api/api.rb >> /log/file 2>&1 & echo $! > my_sinatra_server.pid echo "PID is $(< my_sinatra_server.pid)" else echo "Invalid args" >> $Logfile fi echo "bye:-)" >> $Logfile
What I have runs properly, but I would also have other scripts to be run, and Python and a Nodejs script.
How can I add those as well. Is it similar to
nohup for Ruby? Add a new line of
nohup after that for each script? Will those introduce any delay in handing back control?
And if I want to delegate this to another executable bash file, will it be a simple case of copying all those
nohup commands to the new bash file and return control to the Wifi manager immediately? Will this be much better? How can I do this then?