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.
"bash first.sh" not idea since beginning of script starts "#!/bin/sh", means: "first.sh" , system interpret using "/bin/sh".
"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
- evoke wget etc. absolute paths. or
- 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
Post a Comment