今日登陸阿里雲,發現 阿里雲 推出了 Cloud Shell,本以為是 一個 模擬 終端的一個小工具,體(zhe)驗(teng)一番,發現 竟然 是一個 真實的 被限制的 Linux環境,基於 Alpine Linux。好興奮,有免費的測試機玩了。。。。
常用命令都被軟關聯到了 busybox。測試了下 gcc、apt-get、yum、rpm統統沒有,這樣就有點雞肋了,除了自帶的工具啥都不能安裝。好在默認安裝了 Python、SSH、curl等工具,pip因為權限太低不能安裝庫。
看了下 shell 中的核心命令 aliyun,功能還是很強大的,基本所有 業務都可以操作。
shell@Alicloud:~$ aliyun --help
Alibaba Cloud Command Line Interface Version 3.0.6
Usage:
aliyun
Flags:
--mode use `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair}` to assign authenticate mode
--profile,-p use `--profile
--language use `--language [en|zh]` to assign language
--region use `--region
--access-key-id use `--access-key-id
--access-key-secret use `--access-key-secret
--sts-token use `--sts-token
--ram-role-name use `--ram-role-name
--ram-role-arn use `--ram-role-arn
--role-session-name use `--role-session-name
--private-key use `--private-key
--key-pair-name use `--key-pair-name
--secure use `--secure` to force https
--force use `--force` to skip api and parameters check
--endpoint use `--endpoint
--version use `--version
--header use `--header X-foo=bar` to add custom HTTP header, repeatable
--body use `--body $(cat foo.json)` to assign http body in RESTful call
--pager use `--pager` to merge pages for pageable APIs
--output,-o use `--output cols=Field1,Field2 [rows=jmesPath]` to print output as table
--waiter use `--waiter expr=
--dryrun add `--dryrun` to validate and print request without running.
--quiet,-q add `--quiet` to hide normal output
--help print help
Sample:
aliyun ecs DescribeRegions
Products:
aegis Server Guard
agency agency
alidns Alibaba Cloud DNS
arms Application Real-Time Monitoring Service
batchcompute BatchCompute
bssopenapi bss
ccc cloud call center
cdn Alibaba Cloud CDN
cds CodePipeline
chatbot BeeBot
cloudapi API Gateway
cloudauth ID Verification
cloudphoto Cloud Photos
cloudwf CloudAP
cms Cloud Monitor
cr Container Registry
cs Container Service
csb Cloud Service Bus
dds ApsaraDB for MongoDB
dm Direct Mail
domain domain
domain-intl domain
drds Distributed Relational Database Service
eci Elastic Container Instances
ecs Elastic Compute Service
edas Enterprise Distributed Application Service
elasticsearch elasticsearch
emr E-MapReduce
ess Auto Scaling
green Alibaba Content Security Service
hpc Alibaba Cloud HPC
httpdns HttpDNS
iot Alibaba Cloud IoT
itaas Cloud Display
jaq Mobile Security
kms Key Management Service
live ApsaraVideo for Live
mts ApsaraVideo for Media Processing
nas Network Attached Storage
ons Message Queue
ots Table Store
polardb ApsaraDB for POLARDB
push Alibaba Cloud Mobile Push
qualitycheck Smart Conversation Analysis
r-kvstore ApsaraDB for Redis
ram Resource Access Management
rds ApsaraDB for RDS
ros Resource Orchestration Service
sas-api Situation Awareness Service
slb Server Load Balancer
sts Resource Access Management
vod ApsaraVideo for VOD
vpc Virtual Private Cloud
waf Web Application Firewall
Use `aliyun --help` for more information.
之前 做過 域名API 相關的開發,拿域名入手,aliyun domain –help 可以看到 域名支持的操作,點擊 鏈接可以進入 域名的API 文檔。經過測試,API中的所有操作都可以 支持(很多在 命令幫助中 看不到),比如:QueryDomainList。
shell@Alicloud:~$ aliyun domain --help
Alibaba Cloud Command Line Interface Version 3.0.6
Usage:
aliyun Domain
Product: Domain (domain)
Version: 2016-05-11
Link: https://help.aliyun.com/api/domain
Available Api List:
CheckDomain
CreateOrder
DeleteContactTemplate
GetWhoisInfo
OSuborderDomain
QueryBatchTaskDetailList
QueryBatchTaskList
QueryContact
QueryContactTemplate
QueryDomainBySaleId
QueryDomainList
QueryFailReasonList
QueryOrder
SaveContactTemplate
SaveContactTemplateCredential
SaveTaskForModifyingDomainDns
SaveTaskForSubmittingDomainNameCredential
SaveTaskForSubmittingDomainNameCredentialByTemplateId
SaveTaskForUpdatingContactByTempateId
SaveTaskForUpdatingContactByTemplateId
WhoisProtection
阿里的域名導出不太好用,用 QueryDomainList 接口,做個 域名導出工具,練練手。根據文檔,必須的參數 有 PageNum、PageSize。 執行 aliyun domain QueryDomainList –PageNum 1 –PageSize 10000,就獲取到了 每頁10000條,第一個 的域名數據。將 輸出的 JSON 信息 上傳到 服務器處理(比如PHP),生成 csv 下載。
經過測試 PageSize 最大值為 1000,我 公司賬號裡有上萬條域名數據,需要分多頁下載。考慮到 HTTP 請求的限制,每次只上傳 100 個域名信息。經過一下午的摸索,終於 完美的實現了這個小功能。經過優化,已經比較完美了。按照 Linux 下的慣例, 只需要複製一行 命令即可使用。
最終生成的文件如下:
define('APP_PATH', 'http://www.miaoqiyuan.cn/products/alishell/'); //安裝目錄
define('APP_URL', APP_PATH . 'domain.php'); //程序路徑
define('APP_ACTION', isset($_GET['action']) ? $_GET['action'] : ''); //請求方法
//讀取 YunShell 上傳的信息
$data = json_decode(file_get_contents("php://input"), true);
if (!empty($data) && isset($data['Data']) && isset($data['Data']['Domain'])) {
switch (APP_ACTION) {
case 'tocsv':
//分頁上傳域名數據
if (!isset($_GET['key']) && !is_numeric($_GET['key'])) {
die("Key Error!");
}
$tmp_key = $_GET['key'];
$csv_data = '';
foreach ($data['Data']['Domain'] as $item) {
foreach ($item as $val) {
$csv_data .= $val . "\t";
}
$csv_data .= "\n";
}
$file_name = $tmp_key . '.txt';
file_put_contents($file_name, $csv_data, FILE_APPEND);
echo "Update: " . APP_PATH . "${file_name}";
break;
default:
//根據 總頁數 生成 腳本
if (isset($data['TotalPageNum']) && is_numeric($data['TotalPageNum'])) {
$page_all = (int) $data['TotalPageNum'];
echo "\n\necho All:{$page_all}\n";
$tmp_key = date('Ymdhis');
for ($page_id = 1; $page_id <= $page_all; $page_id++) {
echo "\necho Download {$page_id}/${page_all}\n";
echo 'curl "' . APP_URL . '?action=tocsv&key=' . $tmp_key . '" --data "`' . "aliyun domain QueryDomainList --PageNum ${page_id} --PageSize 100" . '`"';
}
}
break;
}
//結尾輸出換行,防止影響提示符
die("\n");
} else {
//直接訪問,輸出調用命令
echo 'curl ' . APP_URL . ' --data "`aliyun domain QueryDomainList --PageNum 1 --PageSize 100`"|bash';
}
?>
閱讀更多 來一杯82年的Java 的文章