Answer the question
In order to leave comments, you need to log in
I can't understand why the script clears the entire cron, the place of deleting a specific line, how to do it right?
There is a script that should remove one specific line from the cron, but for some unknown reason, it clears all the lines in the cron, I just can’t figure out what the error is.
Here is the part responsible for it
$connect = ssh2_connect('localhost', '22');
ssh2_auth_password($connect, ssh_login, ssh_password);
$stream = ssh2_exec($connect,'cat /var/spool/cron/crontabs/deone');
stream_set_blocking($stream, true);
$path_script = 'user_'.$_SESSION['id'].'_job_'.$id.'.php';
$stream = stream_get_contents($stream);
$stream = str_replace('* * * * * /home/jitter.sh; /usr/bin/flock -xn /tmp/'.$path_script.'.lock -c \'/usr/bin/php -q /var/www/deone/data/www/vk-manager.ru/script/grabber/'.$path_script.' >/dev/null 2>&1\'', '', $stream);
ssh2_exec($connect,'echo -n > /var/spool/cron/crontabs/deone');
ssh2_exec($connect, 'echo "'.$stream.'">> /var/spool/cron/crontabs/deone');
ssh2_exec($connect, '/etc/init.d/cron restart');
}
}
$mysqli->close();
* * * * * /home/jitter.sh; /usr/bin/flock -xn /tmp/user_751_job_11101.php.lock -c '/usr/bin/php -q /var/www/deone/data/www/vk-manager.ru/script/grabber/user_751_job_11101.php >/dev/null 2>&1'
$connect = ssh2_connect('localhost', '22');
ssh2_auth_password($connect, ssh_login, ssh_password);
$stream = ssh2_exec($connect,'cat /var/spool/cron/crontabs/deone');
stream_set_blocking($stream, true);
$stream = stream_get_contents($stream);
$path_script = 'grabber/user_'.$_SESSION['id'].'_job_'.$id.'.php';
$stream = str_replace("* * * * * /usr/bin/php -q /var/www/deone/data/www/vk-manager.ru/script/".$path_script." >/dev/null 2>&1\n",'',$stream);
ssh2_exec($connect,'echo -n > /var/spool/cron/crontabs/deone');
ssh2_exec($connect, 'echo "'.$stream.'">> /var/spool/cron/crontabs/deone');
ssh2_exec($connect, '\etc\init.d\cron restart');
Answer the question
In order to leave comments, you need to log in
In general, yes, it is done wildly crooked. First, the script takes the file from the server, then processes it on its side, then transfers the entire file back. Isn't it easier to "point" process the file on the server side? There is a magic utility sed!
$connect = ssh2_connect('localhost', '22');
ssh2_auth_password($connect, ssh_login, ssh_password);
$stream = ssh2_exec($connect,"sed -i.back 's/* * * * * /home/jitter.sh; /usr/bin/flock -xn /tmp/$path_script.lock -c \'/usr/bin/php -q /var/www/deone/data/www/vk-manager.ru/script/grabber/$path_script >/dev/null 2>&1\'//' /var/spool/cron/crontabs/deone");
ssh2_exec($connect, '/etc/init.d/cron restart');
Why not create one file for one job? And remember its name, then to rewrite or delete it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question