In this short article I show you, how you can extend the functionality of the command line se with your own script.
#!/bin/bash
cmd="$1"
chmod +x "$cmd"
echo "Starting '$cmd'">nohup.out
#(exec nohup $cmd ) 2>/dev/null &
nohup /bin/bash -c "$cmd" </dev/null >nohup.out 2>&1 &
cmd_pid=$!
timeout=120 # seconds
echo "Script was started in background, showing output for max $timeout seconds:"
timeout $timeout tail -f nohup.out &
timeout_pid=$!
wait $cmd_pid
retval=$?
printf "$retval" > /tmp/retval_port_$PORT # ie. /tmp/gotty/retval_port_8091
echo "$(basename $0): Done with retval of: $retval for port: $PORT"
if [ "0" -eq "1" ]; then
echo "UID PID PPID C STIME TTY TIME CMD"
ps -ef | grep '[Tt]ail -f'
fi
kill $timeout_pid