【问题标题】:PHP cron job to start/stop AWS - passing parameters用于启动/停止 AWS 的 PHP cron 作业 - 传递参数
【发布时间】:2016-06-05 02:02:50
【问题描述】:

我这里有这段代码:

#!/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";
?>

如您所见,它需要 3 个参数才能工作。你如何将它们传递给它? 我试过了

php -q /path/public_html/script.php 启动 i-9999 eu-west-c

但没有运气!

应该是……

php -q /path/public_html/script.php?start&i-9999&eu-west-c

?

【问题讨论】:

  • 使用命令行参数应该是php -q /path/public_html/script.php start i-9999 eu-west-c

标签: php amazon-web-services amazon-ec2 cron


【解决方案1】:

要将命令行参数传递给 PHP 脚本,您可能需要查看此Command line Arguments to PHP Script。希望这对某人有所帮助。谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 2015-10-23
    • 1970-01-01
    • 2012-07-03
    • 2011-05-28
    • 2018-05-13
    • 1970-01-01
    • 2021-06-18
    相关资源
    最近更新 更多