执行脚本

服务器常用脚本 #

参考资料 https://github.com/fengyuhetao/shell

常用定时器 #

  • 自动休眠
  • 清楚内存
  • 更新容器内的git项目
  • 定时器日志需要安装邮箱 apt install postfix -y (选择5. Local only)日志在/var/mail/用户下
*/10 * * * * /bin/powersave.sh
*/10 * * * * echo 3 > /proc/sys/vm/drop_caches
0 */2 * * * docker exec zian updategit

powersave.sh #

  • 让系统休眠
  • debian13需安装apt install wtmpdb
#!/bin/bash

logintime=`last docker --time-format iso | head -n1 | awk '{print $6}'`
#logintime="2024-09-11T07:18:18+08:00"
if [ ${#logintime} -eq 5 ];then
    date
    echo "docker there"
else
        logintime=`date -d $logintime +%s`
        logintime=$(expr $logintime)
        now=$(expr `date +%s`)
        now=$(expr $now - $logintime)
        if [ $now -gt 7200 ] ;then
                systemctl suspend
        else
            echo "docker leave" $now
        fi
fi

updategit #

#!/bin/bash

cd /var/www/
command -v unzip >/dev/null 2>&1 || apt install -y unzip
wget github.com/zi-an/zi-an.github.io/archive/refs/heads/master.zip
unzip -o master.zip
rm master.zip

kaibo.sh #

#!/bin/bash

command -v ffmpeg >/dev/null 2>&1 || apt install -y ffmpeg
nohup ffmpeg -re -stream_loop -1 -i bbb.mp4 -c: copy -f flv "$1" &

alias #

alias zian="docker exec -it zian bash"
alias xunlei="docker exec -it xunlei bash"
alias maomiav="docker exec -it maomiav bash"
alias transmission="docker exec -it transmission bash"
alias transmission="docker exec -it transmission bash"
alias v2rayalog="docker logs -fn20 v2raya"
alias dockerps="docker ps -a --format 'table {{.Names}}\t{{.Status}}'"