I’ve done this plenty of other times, just never posted it here. Here’s one I just finished real quick for starting my rtorrent (which likes to die every so often, i think its rutorrent causing it) when it dies. This one is unique in that it must be run in a screen session and like everything else, I tack on the “nohup command &” to ensure it starts in the background…but tbh, now that I look at it, you don’t actually need that since that screen will obviously live on when created whether or not that shell is still alive or not. Ok I’ll shut up.
ps -e | grep rtorrent | grep -v grep | wc -l if [ “$pid” == 0 ]; then screen -S rtor -X quit nohup /usr/bin/screen -dmS rtor rtorrent >/dev/null 2>&1 & fi