I have this command in a bash script called run.sh

 kill $(lsof -t -i:34445)

On a terminal when i run this script using bash run.sh it works. However, i am using crontab to schedule this command. This comes up with the error that

 lsof: command not found

There was also another command that i tried fuser and that didnt work too. Can you tell me what is it that I am doing / not doing that makes this work in one case and not in another

this is my crontab setup


 58 * * * 1-5 bash /dir/run.sh > run.out 2>&1 & 
  • 2
    Try which lsof to see where the binary is. On CentOS, it happens to be in /usr/sbin/. Same with fuser. – Ulrich Schwarz Jan 30 '19 at 15:12
  • 1
    Aside: why are you putting the command in the background with the final &? It's already in the background as it's started by cron. – wurtel Jan 30 '19 at 15:30

Browse other questions tagged or ask your own question.