工作中常用知识记录

本文介绍了自动化运维脚本,包括日志清理、服务监控与重启、Git自动化部署,以及使用Python进行无界面爬虫实现。同时提到了前端启动命令、服务杀进程方法及Redis的使用。此外,还提供了IDEA下载链接和许可证服务器设置的相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

日志清理

while true
do

    cat ./file_name | while read line || [ -n "$line" ]
    do

        procnum=`ps -ef|grep $line |grep -v grep|wc -l`
	    if [ $procnum -eq 0 ]
	    then
	        sh sh start.sh $line
	        echo `date +%Y-%m-%d` `date +%H:%M:%S` $line "restart 服务" >>$basepath/shell.log
                sleep 120
	    fi
	    sleep 1

    done

done

iTerm2 提醒设置
https://www.jianshu.com/p/147e6625678d

# push 脚本
#!/bin/bash
set -x
cd 目录
git pull
git add .
git commit -m "更新配置"
chmod 777 目录/git.sh
pwd
git branch --set-upstream-to=origin/master master
echo "开始push"
pwd
git push --set-upstream origin master
pwd

前端启动命令
pm2 --name=“front” start npm – run dev

杀服务
ps -ef |grep {变量} | grep -v grep | awk ‘{print $2}’ | sed -e ‘s/^/kill -9 /g’ | sh

爬虫

#!usr/bin/python
import sys
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

import time
import redis   # 导入redis 模块
path = '/usr/local/bin/chromedriver'

r = redis.Redis(host=' ', port=6379, decode_responses=True)


def run(username, password, url_type):
    """
    获取 cookie 或者 token,并设置到 redis 中
    key格式为:
    :param username:
    :param password:
    :return:
    """
    # # 无界面浏览器
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    #  browser = webdriver.Firefox()
    browser = webdriver.Chrome(chrome_options=chrome_options,executable_path=path)

    # 有界面
    #  browser = webdriver.Chrome(executable_path=path)
    url = ''
    mq_url = " "
    o_url = " "
    if url_type == "o ":
        url = o_url
    elif url_type == "d ":
        url = mq_url
    else:
        url = mq_url

    browser.get(url)
    time.sleep(2)
    browser.find_element_by_id("username").send_keys(username)
    browser.find_element_by_id("password").send_keys(password)
    browser.find_element_by_id("submit").click()
    time.sleep(3)
    cookie_items = browser.get_cookies()
    cookie_str = ""
    # 组装cookie字符串
    for item_cookie in cookie_items:
        item_str = item_cookie["name"] + "=" + item_cookie["value"] + "; "

        if item_cookie["name"] == 'token':
            token = '"' + item_cookie["value"] + '"'
            r.set(username + '_' + url_type + '_token', token)
            print(username + '_' + url_type + '_token: ' + token)

        cookie_str += item_str

    cookie_str = '"' + cookie_str + '"'
    print(username + '_' + url_type + '_cookie: ' + cookie_str)
    r.set(username + '_' + url_type + "_cookie", cookie_str)
    browser.quit()
    if len(cookie_items) < 3:
        print("执行失败")
        r.set(username + '_' + url_type + '_token', 'false')
        r.set(username + '_' + url_type + "_cookie", 'false')
        return False
    else:
        print("执行成功")
        return True


if __name__ == '__main__':
    """
    需要安装
    1、pip install redis
    2、pip install selenuim
    3、安装 Chromedriver  参考:https://www.cnblogs.com/jasmine0112/p/12745493.html

    """

    print("开始获取 cookie and token 并设置到 redis 中")
    argvs = sys.argv
    print(argvs)
    if len(argvs) == 1:
        print("本地执行")
        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        run(" ", " ", "d")
        run(" ", " ", "o")
    elif len(argvs) != 4:
        print("请输入正确的执行方式")
        print("执行方式: python3 getcookie.py username password oe/ddmq")
    else:
        username = argvs[1]
        passport = argvs[2]
        url_type = argvs[3]
        run(username, passport, url_type)

IDEA
https://download.jetbrains.com/idea/ideaIU-2017.2.7.dmg
2019-12-05 14:37
https://blog.youkuaiyun.com/m0_37540696/article/details/102939088 License server 方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值