I
I
integrall2017-06-07 09:20:04
Task Schedulers
integrall, 2017-06-07 09:20:04

Why doesn't cron execute a php script from the admin with a reboot command, but does it manually?

The script looks like this:

include_once "smsc_api.php"; //прикладываем библиотеку для отправки смс

$doc = new DomDocument;
$doc->validateOnParse = true;

$res = $doc->Load('http://example.ru/feed/'); //Получаем ресурс с сайта
if (!$res) { //если ресурс не получен, значит сервак упал
  exec("service mysqld restart"); //Перезагружаем сервер БД
  list($sms_id, $sms_cnt, $cost, $balance) = send_sms("79176329140", "Server is down. Trying to restart...", 1); // Отправляем смс о том, что СУБД упала и была перезагружена
} else {
  echo "No problem";
}
?>

Manually the script is executed remarkably, and on cron is not present. What am I doing wrong?
Runs in Vesta as admin.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin, 2017-06-07
@kostya_vtomske

do you have www-data in sudouser ?
exec('sudo -u www-data -S /etc/init.d/mysql restart');

S
Saboteur, 2017-06-07
@saboteur_kiev

include_once "smsc_api.php";

And where does your cron start executing, what is its current folder when the script is launched, and does it find this smsc_api.php in it?
Add full paths or cd to cron or script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question