全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1554|回复: 15
打印 上一主题 下一主题

问一个傻逼问题

[复制链接]
跳转到指定楼层
1#
发表于 2019-10-15 19:46:55 来自手机 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
撸甲骨文的API脚本如果撸到了,返回的状态码是多少?(没机器是500,请求过多是429)
推荐
 楼主| 发表于 2019-10-15 19:51:37 来自手机 | 只看该作者
undefined 发表于 2019-10-15 19:50
不用判断,1分钟一次就请求吧

我半分钟一次
2#
发表于 2019-10-15 19:50:24 | 只看该作者
不用判断,1分钟一次就请求吧
4#
发表于 2019-10-15 20:00:11 | 只看该作者
oci-cli吗?200吧,我5秒一次请求,判断的就是stderr和stdout
5#
发表于 2019-10-15 20:03:28 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
dtkevin 该用户已被删除
6#
发表于 2019-10-15 20:04:20 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
7#
 楼主| 发表于 2019-10-15 20:09:15 来自手机 | 只看该作者
yyuueexxiinngg 发表于 2019-10-15 20:00
oci-cli吗?200吧,我5秒一次请求,判断的就是stderr和stdout

那怎么把获取的这个状态码写到一个变量里呢?
8#
发表于 2019-10-15 20:14:03 | 只看该作者
fxzx 发表于 2019-10-15 20:09
那怎么把获取的这个状态码写到一个变量里呢?

我用nodejs写的,没用bash
9#
发表于 2019-10-15 20:17:03 | 只看该作者
怎么弄,那个大佬发出来以下啊
10#
发表于 2019-10-15 20:24:17 | 只看该作者
本帖最后由 tonyma 于 2019-10-15 21:01 编辑

用python吧,readlines() 开到机器邮箱通知,

1、首先要contab定时执行.sh脚本并输出返回的结果在一个.txt里面(代码:/bin/bash /root/oci.sh >/var/tmp/test.txt 2>&1)
2、python 代码读取.txt文件,readlines(),判断返回结果行数组中的关键字error(一般没库存和其他错误内容都是返回一个error)
3、oci.sh (
                  第一行: oci compute instance launch --availability-domain ULJk:AP-SEOUL-1-AD-1 --image(这里是oci 命令)
                  第二行: python jsontest.py
                 )


  1. # -*- coding: UTF-8 -*-
  2. import json
  3. import io
  4. import smtplib
  5. from email.mime.text import MIMEText
  6. def success_mail():
  7.   mail_host = 'smtp.qq.com' #发送发服务器地址
  8.   mail_user = '[email protected]'#发送方邮箱
  9.   mail_pass = '###' #发送方密码
  10.   sender = '[email protected]'
  11.   receivers = ['[email protected]']
  12.   message = MIMEText('successfully open the  machine','plain','utf-8')#发送的内容
  13.   message['Subject'] = 'congratulations!'
  14.   message['From'] = sender
  15.   message['To'] = receivers[0]

  16.   try:
  17.     smtpObj = smtplib.SMTP_SSL("smtp.qq.com",465)
  18.     smtpObj.login(mail_user,mail_pass)
  19.     smtpObj.sendmail(
  20.         sender,receivers,message.as_string())
  21.     smtpObj.quit()
  22.     print('success')
  23.   except smtplib.SMTPException as e:
  24.     print('error',e)
  25. def fail_mail():
  26.   mail_host = 'smtp.qq.com'#发送发服务器地址
  27.   mail_user = '[email protected]'#发送方邮箱
  28.   mail_pass = '###' #发送方密码
  29.   sender = '[email protected]'
  30.   receivers = ['[email protected]']#接收方
  31.   message = MIMEText('fail to open the  machine','plain','utf-8') #发送的内容
  32.   message['Subject'] = 'fail!'
  33.   message['From'] = sender
  34.   message['To'] = receivers[0]


  35.   try:
  36.     smtpObj = smtplib.SMTP_SSL("smtp.qq.com",465)

  37.     smtpObj.login(mail_user,mail_pass)

  38.     smtpObj.sendmail(
  39.         sender,receivers,message.as_string())

  40.     smtpObj.quit()
  41.     print('success')
  42.   except smtplib.SMTPException as e:
  43.     print('error',e)

  44. f = open('/var/tmp/test.txt','r')
  45. lines=f.readlines()
  46. if 'Error' not in lines[2]:
  47.    success_mail()
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-12-12 15:44 , Processed in 0.063304 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表