-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycron.sh
55 lines (52 loc) · 1.61 KB
/
mycron.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
touch crontabFile
while true ; do
echo "Select one of the following options available: "
echo "1. Display crontab jobs."
echo "2. Insert a job."
echo "3. Remove a job."
echo "4. Remove all jobs."
echo "5. Exit."
read input
case $input in
1) crontab -l > crontabFile;
if [[ -s crontabFile ]] ;
then
echo "The command "; awk '{ print$6 }' crontabFile;
echo "will run on "; awk '{ print$1 }' crontabFile; echo "minute(s)";
awk '{ print$2 }' crontabFile; echo "hour(s)"; awk '{ print$3 }' crontabFile;
echo "day of month "; awk '{ print$4 }' crontabFile; echo "month";
awk '{ print$5 }' crontabFile; echo "day of week";
else
echo "No Jobs to Display.";
fi
;;
2) echo "Enter the minute(s) of the time to run (0-59) or * for any minute";
read minutes;
echo "Enter the hour(s) of the time to run (0-23) or * for any hour";
read hour;
echo "Enter the day of the month (1-31) or * for any day";
read day;
echo "Enter the month (1-12) or * for any month";
read month;
echo "Enter the day of the week (0=Sunday, 1-Monday etc) or * for any day";
read weekDay;
echo "Enter the commmand you wish to install";
read command;
crontab -l > crontabFile;
echo "$minutes $hour $day $month $weekDay $command" >> crontabFile;
crontab -i crontabFile;
echo "Cron job installed successfullly.";;
3) echo "Enter the command you wish to delete: ";
read commandDelete;
crontab -l > crontabFile;
sed -i "/$commandDelete/d" crontabFile;
crontab -i crontabFile;
echo "Job deleted successfully.";;
4) crontab -r;
echo "All Cron jobs removed successfully.";;
5) rm crontabFile;
echo "Exiting...";
exit;;
esac
done