vito/app/SSH/Cron/Cron.php
2024-10-01 19:09:38 +02:00

28 lines
578 B
PHP

<?php
namespace App\SSH\Cron;
use App\Models\Server;
class Cron
{
public function __construct(protected Server $server) {}
public function update(string $user, string $cron): void
{
$command = <<<EOD
if ! echo '$cron' | sudo -u $user crontab -; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo -u $user crontab -l; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo 'cron updated!'
EOD;
$this->server->ssh()->exec($command, 'update-cron');
}
}