I am trying to set up a cron job that will keep alive a process that is running on a particular port in a centos server.
Based on the previous discussions I have come up with the following script which will be called by a cron job:
#!/bin/bash
opt="$(lsof -i tcp:9090| awk 'NR!=1 {print $2}')"
echo $opt
if [ -z "$opt" ]
then
# nohup npm start & 1>/dev/null 2>/dev/null &
echo "App Restarted" | mail -s "App is restarted" "myemail"
fi
This gets triggered irrespective of the value in the variable output, not sure what is wrong here.