linux - Issue with scheduling a bash script with crontab -


using:

20 21 * * *  /bin/sh /users/username/documents/first.sh 

to execute script btw have @ top:

#!/bin/sh 

and instead getting this:

you have new mail in /var/mail/username 

with following output:

/users/username/documents/first.sh: line 3: wget: command not found /users/username/documents/first.sh: line 4: wget: command not found 

how fix this?

even though made cron job work somehow, i'd point out "solution" seems irrelevant.

  1. "bash first.sh" not idea since beginning of script starts "#!/bin/sh", means: "first.sh" , system interpret using "/bin/sh".

  2. "cd /users/username/documents" not solve "command not found" issue.

this common issue cron jobs. root cause is: cron jobs (first.sh in case) run in "clean" environment. is, profile not sourced. consequently, path env var contains minimal number of path , unfortunately "wget" not in paths.

solution: simple , straight forward. can

  1. evoke wget etc. absolute paths. or
  2. setup path accordingly (or source in corresponding profiles) @ beginning of script.

for sake of security, prefer call external commands (wget etc.) using absolute paths.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -