Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于启动/停止AWS的PHP cron作业-传递参数_Php_Amazon Web Services_Amazon Ec2_Cron - Fatal编程技术网

用于启动/停止AWS的PHP cron作业-传递参数

用于启动/停止AWS的PHP cron作业-传递参数,php,amazon-web-services,amazon-ec2,cron,Php,Amazon Web Services,Amazon Ec2,Cron,我在这里输入了以下代码: #!/usr/bin/php <?php /* | | ec2-power-button -- @dustyfresh | ./ec2-power-button <start/stop> <instanceID> <region> | | this will toggle an instance on or off, and it's good | for cronjerbs! | */ error_reporting(0);

我在这里输入了以下代码:

#!/usr/bin/php
<?php
/*
|
| ec2-power-button -- @dustyfresh
| ./ec2-power-button <start/stop> <instanceID> <region>
|
| this will toggle an instance on or off, and it's good
| for cronjerbs!
|
*/
error_reporting(0);
$cmd = $argv[1] or die("please supply a command(start/stop)...\n");
$instanceID = $argv[2] or die("please supply an instance ID\n");
$region = $argv[3] or die("Please specify a region. for example: us-east-1\n");

require_once "awssdkforphp/vendor/autoload.php";
use Aws\Ec2\Ec2Client;

$client = Ec2Client::factory(array(
 'key' => '', // your auth API key
 'secret' => '', // your secret API key
 'region' => "$region",
 ));

if($cmd == 'start'){
 $result = $client->startInstances(array(
 'InstanceIds' => array($instanceID,),
 'DryRun' => false,
 ));
} elseif($cmd == 'stop'){
 $result = $client->stopInstances(array(
 'InstanceIds' => array($instanceID,),
 'DryRun' => false,
 ));
}
//print_r($result); // uncomment to see results of request
print "OK\n";
?>
#/usr/bin/php

要将命令行参数传递给PHP脚本,可能需要看一下这个。希望这对其他人有所帮助。感谢您使用命令行参数,应该是
php-q/path/public_html/script.php start i-9999 eu-west-c