#!/bin/bash ## 定时任务 if [ $# -le 5 ];then echo -e "\033[32;1m格式错误\033[0m" echo -e "\033[32;1mUSGE:$0 \"x x x x x [script]\"\033[0m" exit 1 else read -p "Choose User Execute the task[default root]:" user : ${user:=root} u=`cat /etc/passwd | awk -F ':' '{print $1}' |grep $user` if [ -n $u ];then chattr -i /etc/crontab chattr -i /etc/cron.d/ chattr -i /var/spool/cron/ echo $* >> /var/spool/cron/$user chattr +i /etc/crontab chattr +i /etc/cron.d/ chattr +i /var/spool/cron/ else echo -e "\033[31;1m$user is not exists! \033[0m" exit 1 fi fi