I'm fumbling my way through with this one, as a novice with all things linux so please be patient :)
I would like to output the process ID of a program to a file. From my readings this is generally achieved by a special pling variable which linux maintains:
make_something_run.sh &
echo $! > /var/run/someting.pid
however when I try to apply this in my startup script for red5, it creates the pid file successfully but no id is found within. This is the specific script:
start)
echo -n "Starting Red5"
echo -n " "
cd $RED5_HOME
su -s /bin/bash -c "$RED5_HOME/$RED5_PROG.sh &" $RED5_USER
echo "$RED5_HOME/$RED5_PROG.sh &"
## su -s /bin/bash -c "$RED5_HOME/$RED5_PROG.sh > start.log &" $RED5_USER
echo $! > /var/run/red5.pid
wait $!
sleep 2
;;
I've tried with and without the wait $! (which I believe waits for the process to start before writing the file?) with no success. My only other thoughts are to do something fancy with grep and ps aux to extract the number, though I've no idea if that would be a reliable approach.