mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-10 23:41:22 +00:00
~重写 set_cron.sh 尝试修复因为定时任务导致系统crontab内容丢失的问题
This commit is contained in:
@@ -1,27 +1,38 @@
|
||||
|
||||
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}')"
|
||||
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}'| tr -d ' ')"
|
||||
[ ! -w "$crondir" ] && crondir="/etc/storage/cron/crontabs"
|
||||
[ ! -w "$crondir" ] && crondir="/var/spool/cron/crontabs"
|
||||
[ ! -w "$crondir" ] && crondir="/var/spool/cron"
|
||||
[ -z "$USER" ] && USER=$(whoami 2>/dev/null)
|
||||
tmpcron=/tmp/cron_tmp
|
||||
touch "$tmpcron"
|
||||
|
||||
croncmd() { #定时任务工具
|
||||
if [ -w "$crondir" ] && [ -n "$USER" ];then
|
||||
[ "$1" = "-l" ] && cat "$crondir"/"$USER" 2>/dev/null
|
||||
[ -f "$1" ] && cat "$1" >"$crondir"/"$USER"
|
||||
killall -HUP crond 2>/dev/null
|
||||
elif [ -n "$(crontab -h 2>&1 | grep '\-l')" ]; then
|
||||
cronadd() { #定时任务工具
|
||||
if crontab -h 2>&1 | grep -q '\-l'; then
|
||||
crontab "$1"
|
||||
else
|
||||
cat "$1" >"$crondir"/"$USER" && cru a REFRESH "0 0 1 1 * /bin/true" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
cronload() { #定时任务工具
|
||||
if [ -f "$crondir/$USER" ];then
|
||||
cat "$crondir"/"$USER" 2>/dev/null
|
||||
elif crontab -h 2>&1 | grep -q '\-l'; then
|
||||
crontab -l
|
||||
else
|
||||
echo "找不到可用的crond或者crontab应用!No available crond or crontab application can be found!"
|
||||
fi
|
||||
}
|
||||
cronset() { #定时任务设置
|
||||
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
|
||||
croncmd -l >"$tmpcron"
|
||||
sed -i "/$1/d" "$tmpcron"
|
||||
echo "$2" >>"$tmpcron"
|
||||
croncmd "$tmpcron"
|
||||
rm -f "$tmpcron"
|
||||
cronload | grep -v '^$' | grep -vF "$1" >"$tmpcron"
|
||||
[ -n "$2" ] && echo "$2" >>"$tmpcron"
|
||||
cronadd "$tmpcron"
|
||||
#华硕/Padavan固件存档在本地,其他则删除
|
||||
if [ -d /jffs ] || [ -d /etc/storage/ShellCrash ];then
|
||||
mv -f "$tmpcron" "$CRASHDIR"/task/cron
|
||||
else
|
||||
rm -f "$tmpcron"
|
||||
fi
|
||||
sleep 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user