Просмотр исходного кода

Randomize monthly cron job time

Bob Mottram 10 лет назад
Родитель
Сommit
3563f28e8d
1 измененных файлов: 7 добавлений и 4 удалений
  1. 7
    4
      src/freedombone

+ 7
- 4
src/freedombone Просмотреть файл

1060
 function randomize_cron {
1060
 function randomize_cron {
1061
   # The predictable default timing of Debian cron jobs might
1061
   # The predictable default timing of Debian cron jobs might
1062
   # be exploitable knowledge. Avoid too much predictability
1062
   # be exploitable knowledge. Avoid too much predictability
1063
-  # by randomizing the times when cron jobs run 
1063
+  # by randomizing the times when cron jobs run
1064
   if grep -Fxq "randomize_cron" $COMPLETION_FILE; then
1064
   if grep -Fxq "randomize_cron" $COMPLETION_FILE; then
1065
       return
1065
       return
1066
   fi
1066
   fi
1067
 
1067
 
1068
   # randomize the day on which the weekly cron job runs
1068
   # randomize the day on which the weekly cron job runs
1069
   randdow=$(($RANDOM%6+1))
1069
   randdow=$(($RANDOM%6+1))
1070
-  sed -i "s/* * 7/* $randdow/g" /etc/crontab
1070
+  sed -i "s|\* \* 7|* * $randdow|g" /etc/crontab
1071
 
1071
 
1072
   # randomize the time when the weekly cron job runs
1072
   # randomize the time when the weekly cron job runs
1073
   randmin=$(($RANDOM%60))
1073
   randmin=$(($RANDOM%60))
1077
   # randomize the time when the daily cron job runs
1077
   # randomize the time when the daily cron job runs
1078
   randmin=$(($RANDOM%60))
1078
   randmin=$(($RANDOM%60))
1079
   randhr=$(($RANDOM%3+4))
1079
   randhr=$(($RANDOM%3+4))
1080
-  sed -i "s|25 6\t* * *|$randmin $randhr\t|g" /etc/crontab
1080
+  sed -i "s|25 6\t\* \* \*|$randmin $randhr\t* * *|g" /etc/crontab
1081
 
1081
 
1082
   # randomize the time when the hourly cron job runs
1082
   # randomize the time when the hourly cron job runs
1083
   randmin=$(($RANDOM%60))
1083
   randmin=$(($RANDOM%60))
1084
-  sed -i "s|17 *\t* * *|$randmin *\t|g" /etc/crontab
1084
+  sed -i "s|17 \*\t|$randmin *\t|g" /etc/crontab
1085
 
1085
 
1086
+  # randomize monthly cron job time and day
1087
+  sed -i "s|52 6\t|$randmin $randhr\t|g" /etc/crontab
1088
+  sed -i "s|\t1 \* \*|\t$randdom * *|g" /etc/crontab
1086
   echo 'randomize_cron' >> $COMPLETION_FILE
1089
   echo 'randomize_cron' >> $COMPLETION_FILE
1087
 }
1090
 }
1088
 
1091