I have setup and cron to check if a port is busy or free and if its free then it sends and email and then start golang api service
send mail is working properly but api server is not getting started
following is my crontab file
*/2 * * * * /home/ubuntu/sh/projectrun.sh
It runs projectrun.sh file every 2 minute, following is my code in this sh file
#!/bin/bash
lsof -i :8080 | grep LISTEN || echo "Not listening" | curl "http://mysiteurl.com/serverlog/?s=cron"
lsof -i :8080 | grep LISTEN || echo "Not listening" | tmux new-session -d -s bkapi3_session 'bkapi'
first line is executing properly as I am getting mails regulary but second command is not working, it works if I run this command directly from console like
lsof -i :8080 | grep LISTEN || echo "Not listening" | tmux new-session -d -s bkapi3_session 'bkapi'
Not sure what is the issue and how to resolve it