forked from nbtafelberg/opensimscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandtoregions.php
52 lines (45 loc) · 1.24 KB
/
commandtoregions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
function dolog($message) {
$message = date("H:i:s") . " - $message" . PHP_EOL;
print($message);
flush();
ob_flush();
}
function fakeget($param) {
global $arguments;
for ($i = 0; $i < count($arguments); ++$i) {
$key = explode("=", $arguments[$i])[0];
$value = explode("=", $arguments[$i])[1];
if ($key === $param) {
return $value;
}
}
return "";
}
function getter($param) {
$test = fakeget($param) . "";
if ($test !== "") {
dolog($param . "=" . $test);
return $test;
}
return readline($param . ":");
// return filter_input(INPUT_POST, $param);
}
function docommand($cmd) {
$screens = shell_exec("screen -r");
$screenlist = explode(PHP_EOL, $screens);
foreach ($screenlist as $regionname) {
$regionname=$regionname . "\t";
dolog(explode("\t",$regionname)[1]);
$shortname = explode("\t", $regionname)[1];
if($shortname!=="" && strpos($shortname,"robust")===false) {
dolog($cmd . " .. " . $regionname);
$torun = 'screen -S ' . $shortname . ' -p 0 -X stuff "' . $cmd . '^M"';
dolog($torun);
exec($torun);
sleep(50);
} else{
echo "Cannot restart robust";
}
}
}