php emploi Cron de (à commande pour être exact)
Question
Je veux exécuter un script juste une fois en mettant en place une tâche cron en utilisant « à » commande. J'utilise maintenant:
<?php
include "config.php";
if (isset($_POST['add']))
{
$sql = mysql_query("INSERT INTO {$table}(msg) VALUES('{$_POST['msg']}')");
if ($sql)
{
$cmd = "wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];
exec($cmd);
echo exec("atq");
echo $cmd;
}
exit();
}
echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>";
echo "<input type='text' name='msg' />";
echo "<input type='text' name='runat' />";
echo "<input type='submit' name='add' />";
echo "</form>";
?>
Toutefois, cela ne semble pas fonctionner. Est-ce que je fais ce droit? Ou pourriez-vous recommander autre chose?
La solution
Vous utilisez la commande at
dans le mauvais sens. Vous devez écho commande et passez à at
. Essayez comme ça:
$cmd = "echo wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow