Shell 脚本记录

监控服务器状态发送给 Incoming Webhooks

#!/bin/bash  

STATE=`top -b -n 1 | grep 'B Mem'`
URL='https://hook.bearychat.com/=bwGFg/incoming/xxxxxxxxxx'
TIME=$(date "+%Y-%m-%d %H:%M:%S")
curl ${URL} -H 'Content-Type: application/json' -d '{"text": "腾讯云服务器状态","attachments": [{"title": "内存 '"${TIME}"'","text":"'"${STATE}"'","color": "#ffa500"}]}'

清理 buff/cache

sync && echo 1 > /proc/sys/vm/drop_caches
sync && echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches

开机执行 shell 脚本

vim /etc/rc.d/rc.local
# 添加
sh /root/sh/auto.sh

在 centos 7 中,/etc/rc.d/rc.local 文件的权限被降低了,开机的时候执行在自己的脚本是不能起动一些服务的,执行下面的命令可以文件标记为可执行的文件

chmod +x /etc/rc.d/rc.local 

selenium 内嵌窗口定位滚动

Selenium 配合 Chromedriver 爬取艺龙评价时,存在内嵌窗口,直接 JS 无法滚动,这里使用如下操作方法

if spider.name == 'elong':
	for i in range(2):
		rand = random.uniform(1, 4)
		time.sleep(rand)
		drag = self.driver.find_element_by_xpath("//li[@class='s_bdt'][last()-1]")
		self.driver.execute_script("arguments[0].scrollIntoView();", drag)
		time.sleep(2)
else:
	for i in range(2):
		rand = random.uniform(1, 4)
		time.sleep(rand)
		js = "window.scrollTo(0,document.body.scrollHeight)"
		self.driver.execute_script(js)
print('Chrome driver success...')