knowledge-work-plugins MCP连接器实战:一键打通Slack、Notion、HubSpot等20+款SaaS工具
2026/9/15 15:06:43
阿里云Instant计算服务,获取正在运行的作业实例的IP地址。快速批量查询所有运行中作业的IP地址。
#!/bin/bash# 阿里云Instant计算服务作业IP地址查询脚本REGION="cn-hangzhou"# 查询所有作业的IP地址jobs=$(aliyun ehpcinstant ListJobs --region"$REGION"2>/dev/null)if[-z"$jobs"];thenecho"查询失败或没有作业"exit1fijob_ids=$(echo"$jobs"|jq -r'.JobList[].JobId')forjob_idin$job_ids;doif[-z"$job_id"];thencontinuefiexecutors=$(aliyun ehpcinstant ListJobExecutors\--region"$REGION"\--JobId"$job_id"\--TaskName Task0\--PageSize100\2>/dev/null)echo"$executors"|jq -r'.Executors[] | .IpAddress[0]'2>/dev/nulldone|sort-u>running_ips.txtecho"IP地址已保存到 running_ips.txt"wc-l running_ips.txtREGION="cn-hangzhou"脚本默认使用杭州区域,如需修改为其他区域,请更改此变量。
jobs=$(aliyun ehpcinstant ListJobs --region"$REGION"2>/dev/null)调用阿里云CLI获取当前区域下的所有作业列表。
job_ids=$(echo"$jobs"|jq -r'.JobList[].JobId')使用jq工具从返回的JSON数据中提取所有作业的ID。
forjob_idin$job_ids;doexecutors=$(aliyun ehpcinstant ListJobExecutors\--region"$REGION"\--JobId"$job_id"\--TaskName Task0\--PageSize100\2>/dev/null)echo"$executors"|jq -r'.Executors[] | .IpAddress[0]'2>/dev/nulldone对每个作业调用ListJobExecutors接口获取执行器信息,并提取IP地址。
done|sort-u>running_ips.txt将所有IP地址排序并去重,最终保存到running_ips.txt文件中。
安装阿里云CLI
# Linux/Maccurl-s https://aliyuncli.alicdn.com/aliyun-cli.sh|bash配置凭证
aliyun configure安装jq工具
# Ubuntu/Debiansudoapt-getinstalljq# CentOS/RHELsudoyuminstalljq# macOSbrewinstalljq# 添加执行权限chmod+x get_running_ips.sh# 运行脚本./get_running_ips.shIP地址已保存到 running_ips.txt 25 running_ips.txt查看IP地址文件:
catrunning_ips.txtcn-hangzhou区域,如需查询其他区域,请修改REGION变量Task0任务PageSize为100/dev/null,确保静默运行阿里云CLI和jq工具,实现了批量获取Instant计算服务作业IP地址的功能。