bash cronjob continues to create a new process even though my
if statement tells it not to run if the process or port already exists...
*/1 * * * * root /opt/script.sh
* * * * * /opt/script.sh
the script opens a port so i tried checking port number using
lsof to determine if the script was executed.
#!/bin/bash port='1234' if ! lsof -i | grep -o $port; then command ... fi
but that didnt work, every 60 seconds another script.sh is executed and somehow there are multiple processes occupying port 1234. so i tried using
ps instead of lsof.
#!/bin/bash c=$(sudo ps aux | grep -o '[s]cript\.sh') if [[ $c != 'script.sh' ]]; then command ... fi
but that doesnt work either. whats going on here? maybe im misunderstanding how cronjobs work, because i cant figure out why the if statements arent working and preventing the command from executing again and again.
im using ubuntu 16.04, fully updated.