Linux将磁盘格式从MBR转换到GPT
利用gdisk工具进行分区转换: [root@localhost /]# yum install -y gdisk 转换/dev/sda2分区,sda1分区为系统启动分区,不需要转换。 [root@localhost /]# gdisk /dev/sda2 GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): 输入y,开始: OK; writing new GUID partition table (GPT) to /dev/sda2. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot. The operation has completed successfully. [root@localhost /]# 查看分区类型: [root@localhost /]# fdisk -l /dev/sda2 WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 磁盘 /dev/sda2:298.4 GB, 298364960768 字节,582744064...
Python的requests模块忽略SSL证书验证警告
报错信息如下: requests.exceptions.SSLError: HTTPSConnectionPool(host='59.197.228.154', port=443): Max retries exceeded with url: /api/datetime (Caused by SSLError(SSLCertVerificationError("hostname '59.197.228.154' doesn't match '124.95.133.232'"))) 解决办法如下: 创建一个 requests 会话对象,并在该会话中全局禁用 SSL 证书验证警告。 import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning # 禁用 InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # 创建一个会话对象 session = requests.Session() session.verify = False response = session.get('https://127.0.0.1') print(response.text)
获取内网时间服务器时间并设置本机时间
脚本如下: import requests import json import os import datetime #写日志函数 def errorlog(message): fileName='/opt/error.log' with open(fileName,'a')as file: file.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+message+'\n') #从内网时间服务器获取时间 url='http://59.197.228.154/api/datetime' ret= requests.get(url) rs = json.loads (ret.text)['result']['datetime'] #格式化时间 settime = datetime.datetime.strptime(rs, "%Y-%m-%d %H:%M:%S") nowtime = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S") print (settime,nowtime) #时间差小于10就同步时间 if (abs(nowtime - settime)).seconds 10: try: os.system("date -s '%s'"%(str(rs))) except: errorlog('时间设置失败!') errorlog('成功!') else: errorlog('时间超限!') Python3 运行测试成功。  
循环检测服务器某个端口是否开放
脚本如下: import socket import datetime import time def check_port(host, port): try: socket.create_connection((host, port), timeout=1).close() return True except socket.error as e: return False host = '166.166.166.24' port = 5236 while True: with open('test.log', 'a') as file: if check_port(host, port): file.write(str(datetime.datetime.now()) + f" Port {port} on {host} is open.\n") else: file.write(str(datetime.datetime.now()) + f" Port {port} on {host} is closed or unreachable.\n") file.close() time.sleep(10) 站长已经使用python3.6验证通过。
解决:sqlalchemy.orm.exc.UnmappedInstance...
错误的语句为: message = Message.query.filter(message_id == Message.id) db.session.delete(message) db.session.commit() 更改为: message = Message.query.get(message_id) db.session.delete(message) db.session.commit() 重新执行删除,成功。
关闭笔记本自带键盘
左下角搜索栏中搜索cmd,以管理员身份运行,在弹出的窗口中将下面这段代码输入进去,并回车。 sc config i8042prt start= disabled 重启,笔记本自带键盘关闭如果想恢复,只要外置键盘以同样方法输入下面这个代码,重启即可。 sc config i8042prt start= auto