问题
I have a script that a developer wrote for me which performs various functions mainly related to ffmpeg. When I run the script manually using
sh /home/site/rawvids/encode.sh > /home/site/rawvids/log.txt
The script runs fine but when it runs through cron it fails with error code 127
Any ideas?
ls -l
on the script shows:
-rwxrwxrwx 1 site nobody 3786 Jul 23 17:07 /home/site/rawvids/encode.sh*
回答1:
Error 127 means "command not found".
It is likely that you run in the script some commands that are not in the of cron
(you can see what cron's PATH is, if you look at /etc/crontab
).
You can check your current PATH in the shell:
$ echo $PATH
And then copy this PATH to the beginning of the script:
PATH=...
Instead of ...
you must write the line that you've got earlier (using echo $PATH
).
Also check if you have shebang line #!/bin/sh
at the beginning of the script. It is import if you start script without sh
in the command line.
Also it would be great if you could show us the line from /etc/crontab
that runs the script.
回答2:
Most likely you're either depending on an environment variable which isn't set for cron (I'm not sure if cron uses any?) or the permissions cron is running under are wrong. If you're piping the output like that in the cron version, does it get any output?
回答3:
same ..., well i just can stand these path issues , i set up a symbolic link to the ffprobe path or whatever is missing , something like
ln -s /usr/local/bin/ffprobe /home/ec2-user/.rvm/rubies/ruby-2.3.0/bin/ffprobe
来源:https://stackoverflow.com/questions/11674766/script-does-not-run-under-cron-but-runs-manually