I would like the ability to remote start/stop ssh on one of my Ubuntu 10.04 systems (non-FQ). I have the following cron PHP script that runs once a minute and checks a URL for whether the services should be started or stopped:
Code:
$url = 'http://...'; // URL where I remote set start/stop
$pid = exec("/usr/bin/pgrep sshd"); // Get PID of sshd if already running
$pid = trim($pid);
if (($f = file_get_contents($url)) && preg_match("/^((?:start|stop))\s*$/", $f,
$matches)) {
if (($matches[1] == 'start') && ! ctype_digit($pid)) {
exec("service ssh start");
} elseif (($matches[1] == 'stop') && ctype_digit($pid)) {
exec("service ssh stop");
}
}
The script works fine when run manually. When cron executes however, I get the following error via email and ssh is not started/stopped:
Code:
exec: 129: start: not found
I found a reference to reinstalling udev and upstart, but still get the same behavior.
I have also tried replacing "service ssh" with "/etc/init.d/ssh".
Any thoughts on what else to try?