vim /usr/bin/cron.sh #插入如下内容 #!/bin/bash source ~/.bashrc etime=`date -d "0 days ago" +%Y%m%d_%H%M%S` if [ "$1" = "-r" ] ; then echo "命令危险已经被禁用" echo "Exit..." exit 2 fi if [ "$1" = "-l" ] ; then /usr/bin/crontab -l exit 0 fi if [ "$1" = "-e" ] ; then mkdir -p ~/cronbak /usr/bin/crontab -l > ~/cronbak/cron.bak.$etime.a /usr/bin/crontab -e /usr/bin/crontab -l > ~/cronbak/cron.bak.$etime.b fi #linux
chmod 755 /usr/bin/cron.sh vim /etc/bashrc
插入如下内容 在末尾
alias crontab='/usr/bin/cron.sh'
source /etc/bashrc
效果如下