P1
На сайте с 26.04.2008
Offline
50
30 марта 2009, 18:46
4910
Cron выбрасывает ошибку 127 при попытке запустить php скрипт. В чем может быть проблема?
Указал путь от корня:
/www/site.ru/papka/scr.php
poiuyt1234 добавил 30.03.2009 в 22:57
А при запуске cron задания из под root’а выдает ошибку 2
poiuyt1234 добавил 30.03.2009 в 23:10
В скрипте есть инклюды
S
На сайте с 01.04.2008
Offline
91
Я надеюсь в кроне так прописано:
/usr/local/bin/php /www/site.ru/papka/scr.php
ну или:
/usr/bin/php /www/site.ru/papka/scr.php
?
Править домен летит Айболит. И одно только слово твердит: — DNS! DNS! DNS!
На сайте с 04.07.2007
Offline
215
[borisko@vaiofw ~]$ nonexistent
bash: nonexistent: команда не найдена
[borisko@vaiofw ~]$ echo $?
127
127 возвращается, если исполняемый файл не найден (ну или еслои php это вернул, что врядли). Уточните путь к интерпретатору у хостера/админа.
С уважением, Борис Долгов.
Администрирование, дешевые лицензии ISPsystem, Parallels, cPanel, DirectAdmin, скины, SSL — ISPlicense.ru (http://www.isplicense.ru/?from=4926)
На сайте с 04.07.2007
Offline
215
[borisko@vaiofw ~]$ nonexistent
bash: nonexistent: команда не найдена
[borisko@vaiofw ~]$ echo $?
127
127 возвращается, если исполняемый файл не найден (ну или если php это вернул, что врядли). Уточните путь к интерпретатору у хостера/админа.
A5
На сайте с 06.08.2006
Offline
46
У меня в кроне работает таким образом
php /home/user/public_html/code.php
Панель Cpanel.
poiuyt1234
Скорее всего пропущен какой-то каталог. Например, /home/poiuyt1234/www/site.ru/papka/scr.php или /var/www/site.ru/papka/scr.php или
На сайте с 28.08.2008
Offline
560
К php тоже нужно указывать полный путь.
Проверить путь к php можно командой: wich php
A5
На сайте с 06.08.2006
Offline
46
Himiko:
К php тоже нужно указывать полный путь.
Проверить путь к php можно командой: wich php
Наверное, автор допустил опечатку, и имелось в виду which php.
На сайте с 28.08.2008
Offline
560
Art569:
Наверное, автор допустил опечатку, и имелось в виду which php.
Спасибо за поправку.
Это была опечатка)
На сайте с 02.11.2002
Offline
241
Himiko:
К php тоже нужно указывать полный путь.
Совсем необязательно, если в кроне выставлена переменная PATH.
There are two types of people in this world:
1. Those who can extrapolate from incomplete data.
На сайте с 08.08.2007
Offline
111
Lupus:
Совсем необязательно, если в кроне выставлена переменная PATH.
правила хорошего тона, ВСЕГДА вызывать программу, указывая полный путь, а то к примеру вам в root может попасть скриптик php который и php запустит, как вы хотите, и чёрных дел наделает =)
Администрирование, Linux, Cisco, Juniper
На сайте с 02.11.2002
Offline
241
Zaqwr:
к примеру вам в root может попасть скриптик php который и php запустит, как вы хотите, и чёрных дел наделает =)
Что-то или я не выспался или вы туманно выразились. Куда может попасть? Что наделает? Какое это имеет отношение к cron tabs?
I’m trying to get my crontab to run a few rake tasks for a rails app, but it seems to always exit with the status of 127, in my syslog it look like this:
Jun 7 05:10:01 ip-10-170-122-226 CRON[15664]: (deploy) CMD (cd /home/deploy/apps/dashboard/current && bundle exec rake some:task
Jun 7 05:10:01 ip-10-170-122-226 CRON[15662]: (CRON) error (grandchild #15664 failed with exit status 127)
It seems that 127 is like «command not found error» or something, so I’ve used the full paths to the bins even so like bundle was /usr/local/bin/bundle
, The task runs fine outside of cron just running it in shell.
My crontab is simplily just:
*/10 * * * * cd /home/deploy/apps/dashboard/current && bundle exec rake some:task
Does maybe my crontab need #!/usr/bin
or something at the top?
update
To just test it, it does seem to run this just fine:
*/1 * * * * /usr/bin/touch /home/deploy/cron-test.txt
So that leads me to think its like a PATH varible thing, but I don’t know how to get the right path vars in there, any thoughts?
I am executing a script manually on my UNIX system manually, it runs successfully and updated required records in ORACLE database. How ever when I exwcute the same script with crontab my process exits with the error code 127.
On analysing further, I got there is some problem in these statements.
LOGFILE=sachin
ORALOGIN=abc/abc@abcd
cmd=’sqlplus ${ORALOGIN} < SQLS >> ${SVC_HOME}/LOGFILES/${LOGFILE}.date +%Y-%m-%d
‘;
eval $cmd
Please suggest a solution
asked Nov 27, 2009 at 8:50
Sachin ChourasiyaSachin Chourasiya
20.6k32 gold badges86 silver badges98 bronze badges
Are you sure that ${ORALOGIN}
and ${LOGFILE}
are valid ENV variables when cron executes the script?
Sometimes scripts that work for users don’t work for cron because cron executions don’t have all the ENV variables that users have.
answered Nov 27, 2009 at 8:53
Arkaitz JimenezArkaitz Jimenez
22.3k11 gold badges74 silver badges104 bronze badges
1
In the interactive enviroment do
env | grep ORACLE
Long time since I’ve used sqlplus, but I recall it required some environment variables to function (ORACLE_HOME?) and I’m suspecting your cron job environment does not have these set.
answered Nov 27, 2009 at 9:17
Solution 1
Exit status 127 is set by bash when it can not find the command (see Advanced Bash Scripting).
To make the debugging easier, you should put all the stuff in a script. Make sure that the script is executable and starts with the interpreter name and path:
#! /bin/bash
cd /.../ && next_command
You should have the crontab line similar to:
*/10 * * * * cd /home/deploy/apps/dashboard/current && /PATH_TO/bundle exec rake some:task
or set the PATH variable in crontab:
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/PATH_TO_bundle
*/10 * * * * cd /home/deploy/apps/dashboard/current && /PATH_TO/bundle exec rake some:task
Solution 2
See man 5 crontab
how to setup PATH for your cron jobs.
Related videos on Youtube
12 : 47
Cron Jobs For Beginners | Linux Task Scheduling
15 : 52
After Effect Installation Failed| After Effect Not Install |Sorry, installation failed Error Code127
02 : 57
DevOps & SysAdmins: /etc/cron.hourly/asl exited with return code 127 (2 Solutions!!)
09 : 55
exit status code of a command | exit command in shell script | why to use exit command & exit codes
02 : 32
DevOps & SysAdmins: Cron fails with exit status 127 (3 Solutions!!)
Comments
-
I’m trying to get my crontab to run a few rake tasks for a rails app, but it seems to always exit with the status of 127, in my syslog it look like this:
Jun 7 05:10:01 ip-10-170-122-226 CRON[15664]: (deploy) CMD (cd /home/deploy/apps/dashboard/current && bundle exec rake some:task Jun 7 05:10:01 ip-10-170-122-226 CRON[15662]: (CRON) error (grandchild #15664 failed with exit status 127)
It seems that 127 is like «command not found error» or something, so I’ve used the full paths to the bins even so like bundle was
/usr/local/bin/bundle
, The task runs fine outside of cron just running it in shell.My crontab is simplily just:
*/10 * * * * cd /home/deploy/apps/dashboard/current && bundle exec rake some:task
Does maybe my crontab need
#!/usr/bin
or something at the top?
update
To just test it, it does seem to run this just fine:
*/1 * * * * /usr/bin/touch /home/deploy/cron-test.txt
So that leads me to think its like a PATH varible thing, but I don’t know how to get the right path vars in there, any thoughts?
-
crontab commands are executed by
/bin/sh
or by shell specified in theSHELL
variable, so it is OK to use ‘cd’, shell redirection, variable expansion, conditions etc. in crontabs. -
We try and avoid pointing people straight to a man page. You should answer the question and point to the man page for further reading.
-
Welcome to Server Fault! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
-
well, regardless it was my Path vars, I’m not sure if this is the best route to take but what I did was just set copy my PATH var string from my env, and paste it the same to the top of the crontab file, is there a way for it to get pulled in the same as my ENV without having to paste it in? Otherwise if I change my ENV path vars I’ll have to make sure my crontab is updated.
Recents
Related
I’m stuck with the following (simple) problem :
I want a script to be executed every 10 minutes. This script calls executable files. I use crontab and ksh on a AIX 5.3 system.
The script makes use of relative paths, but changing the executable path to absolute didn’t make any difference. So, after a few tries and this answer, I came up with the following crontab entry (*/10 doesn’t work)
rs14:/home/viloin# crontab -l
0,10,20,30,40,50 * * * * cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh
here is the script :
#!/bin/ksh
Main(){
printf "executed in : %sn" $(pwd);
executableFile 2>/dev/null 1>&2;
exeResult=$?; # expected return value : 90
printf "%sn" $exeResult;
}
Main;
Here is the output when I run the command manually :
rs14:/home/viloin/cardme/bin# cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh
executed in : /home/viloin/cardme/bin
90
And finally the output when crontab runs it for me (from mail) :
Subject: Output from cron job cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh, viloin@rs14.saprr.local, exit status 0
Cron Environment:
SHELL = /usr/bin/sh
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin
CRONDIR=/var/spool/cron/crontabs
ATDIR=/var/spool/cron/atjobs
LOGNAME=viloin
HOME=/home/viloin
Your "cron" job executed on rs14.saprr.local on Wed Aug 24 11:50:00 CEST 2016
cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh
produced the following output:
executed in : /home/viloin/cardme/bin
127
*************************************************
Cron: The previous message is the standard output
and standard error of one of your cron commands.
My file myScript.ksh has all rights :
rs14:/home/viloin/cardme/bin# ll -al myScript.ksh
-rwxrwxrwx 1 viloin cardme 174 Aug 24 10:54 myScript.ksh
To make sure that my executableFile is not really exiting with code 127, I used the echo binaries, renamed it and I have the same behavior (Except that it returns 0 instead of 90 when I run the command manually).
What is causing this difference between manually typing the command and asking crontab to do it for me ?