-
Notifications
You must be signed in to change notification settings - Fork 1
/
crontab_manager
54 lines (47 loc) · 1005 Bytes
/
crontab_manager
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
#!/bin/bash
### CRONTAB BACKUP MANAGER ###
#
#It will let you migrate users' crontab using crontab and some input/output redirections :)
#
dir_name=crontabz;
function backup_crontab{
mkdir $dirname;
for user in `cat /etc/cron.allow`
do crontab -l -u $user > $dirname/cron_$user;
done
tar -cvzf backup.tgz $dirname;
exit 0;
}
#Now you should move backup.tgz where needed, then restore
function restore_crontab{
tar xfv backup.tgz;
cd $dirname;
for file in `ls -m1`
do echo `basename $file` | sed -s 's/\([a-z]\)*_//' >> temp ;
done ;
for user in `cat temp`
do cat cron_$user | crontab -u $user - ;
done;
rm -f temp;
exit 0;
}
function usage{
echo "Usage: basename $0 { backup | restore }"
}
if [ $# -ne 1 ]
then
usage;
exit 1;
else
case $1 in
backup)
backup_crontab;
;;
restore)
restore_crontab;
;;
*)
usage;
exit 1;
esac
fi