crontab.sh
#!/bin/bash
read -p "请输入分钟信息(0‐59):" min
read -p "请输入小时信息(0‐23):" hour
read -p "请输入日期信息(1‐31):" date
read -p "请输入月份信息(1‐12):" month
read -p "请输入星期信息(0‐6):" week
read -p "请输入计划任务需要执行的命令或脚本:" program
echo "$min $hour $date $month $week $program" >> /etc/crontab
验证:
[root@logstash ~]# sh crontab.sh
请输入分钟信息(0‐59):10
请输入小时信息(0‐23):2
请输入日期信息(1‐31):2
请输入月份信息(1‐12):2
请输入星期信息(0‐6):0
请输入计划任务需要执行的命令或脚本:date.sh
[root@logstash ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
10 2 2 2 0 date.sh
[root@logstash ~]#