Récupère les SPAMs contenus dans le dossiers .Junk des comptes d'un serveur mail. Les SPAMs sont appris puis effacés.
1 #!/bin/bash
2 ###############################################################################
3 #
4 # mysa-lear : Donne à apprendre les dossiers ".Junk" des comptes mail d'un serveur
5 #
6 # Remarque :
7 # - Les comptes doivent être de la forme $VBOX_PATH/_domaine_/_user_/
8 #
9 # by Guillaume Kulakowski a.k.a LLaumgui <guillaume at llaumgui dot com>
10 # Version 1.0
11 #
12 ###############################################################################
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not,
25 # - write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 # - See http://www.gnu.org/licenses/gpl.html
28 ###############################################################################
29
30 # Mails
31 MAIL_SUBJECT="spamassassin for $(hostname)"
32 #MAIL_FROM="spamassassin@$(hostname)"
33 MAIL_TO=root
34
35 BOX_PATH=/home/vbox
36 TRASH_PATH=/home/vbox/scenario-paintball.com/trash
37 NB_SPAM=0
38
39 # On parcour les comptes mails
40 for spam in $VBOX_PATH/*/*/.Junk/cur/*; do
41 #echo "$spam"
42 sa-learn --spam "$spam" > /dev/null
43 rm -f $spam
44 NB_SPAM=$[$NB_SPAM+1]
45 done;
46
47 # NB de SPAM dans le dossier trash :
48 NB_SPAM_TRASH=$(ls $TRASH_PATH/cur/| wc -l)
49
50 # Rapport par mail :
51 MAIL_BODY="$NB_SPAM SPAM appri(s) par spamassassin.\n\n$NB_SPAM_TRASH SPAM dans le dossier Trash."
52 #echo -e $MAIL_BODY
53 echo -e $MAIL_BODY | /bin/mail -s "$MAIL_SUBJECT" $MAIL_TO
This object make a tick system that could make operate some jobs at same time. This is like a cron job, but more simpler.
1 <?php
2
3 class tick {
4 private $ticks = array();
5 private $ok;
6
7 static public $instance = false;
8
9 public static function GetInstance() {
10 if (!self::$instance) {
11 self::$instance = new tick();
12 }
13 return self::$instance;
14 }
15
16 private function __construct() {
17 $this->ok = true;
18 }
19
20 /**
21 * Adding a job to the tick list $tickname
22 *
23 * @param string $tickname
24 * @param string $jobname
25 * @param string $function Function to call
26 * @param array $params Parameters send to the $function
27 * @param boolean $temporary Make the job temporary (will be deleted on next execution of the tick)
28 * @param object $object Reference to an object if $function is a method
29 * @return boolean
30 */
31 public function addJob($tickname,$jobname,$function,$params,$temporary=0,$object=null) {
32 if (isset($this->ticks[$tickname])) {
33 if (!is_null($object)) {
34 $this->ticks[$tickname]['jobs'][] = array(
35 'jname' => $jobname,
36 'function' => $function,
37 'params' => $params,
38 'temporary' => $temporary,
39 'objectRef' => &$object
40 );
41 } else {
42 $this->ticks[$tickname]['jobs'][] = array(
43 'jname' => $jobname,
44 'function' => $function,
45 'params' => $params,
46 'temporary' => $temporary
47 );
48 }
49 return true;
50 }
51 return false;
52 }
53
54 /**
55 * Create a tick if not exist
56 *
57 * @param string $name
58 * @param int $timer Number of seconds before the next tick
59 * @return boolean
60 */
61 public function setTick($name,$timer) {
62 if (!isset($this->ticks[$name])) {
63 $this->ticks[$name] = array(
64 'timer' => $timer,
65 'reference' => time(),
66 'tickOn' => strtotime("+$timer seconds"),
67 'jobs' => array()
68 );
69 return true;
70 }
71 return false;
72 }
73
74 /**
75 * Delete a tick
76 *
77 * @param string $name
78 * @return boolean
79 */
80 public function delTick($name) {
81 if (isset($this->ticks[$name])) {
82 unset($this->ticks[$name]);
83 return true;
84 }
85 return false;
86 }
87
88 public function doAllTicks() {
89 $curtime = time();
90
91 foreach($this->ticks as $name => $options) {
92
93 if ($options['tickOn']<=$curtime) {
94 echo $options['tickOn']," - $curtime\n";
95
96 foreach ($options['jobs'] as $functions) {
97
98 if (!$functions['temporary']) {
99 $jlist[] = $functions;
100 }
101
102 if (!$this->ircmain->ok) {
103 continue;
104 }
105
106 switch (isset($functions['objectRef'])) {
107 case true:
108 if (!is_object($functions['objectRef'])) {
109 throw new Exception('The objectRef for tick '.$name.' at job '.$functions['jname'].' is not an object.',0);
110 }
111 //print_r($functions);break;
112 call_user_func_array(array($functions['objectRef'],$functions['function']),$functions['params']);
113 break;
114
115 case false:
116 call_user_func_array($functions['function'],$functions['params']);
117 break;
118 }
119
120 }
121
122 $options['jobs'] = $jlist;
123
124 $this->ticks[$name] = array(
125 'timer' => $options['timer'],
126 'reference' => time(),
127 'tickOn' => strtotime("+{$options['timer']} seconds"),
128 'jobs' => $options['jobs']
129 );
130
131 echo "newTickOn {$this->ticks[$name]['tickOn']}\n";
132
133 }
134
135 }
136
137 return true;
138
139 }
140 }
141
142 ?>
yum-check permet l'envoi par mail d'un "yum check-update" mis en forme. A appeler dans une tâche cron
1 #!/bin/zsh
2 ###############################################################################
3 #
4 # yum-check : Envoi par mail d'un "yum check-update" mis en forme
5 #
6 # by Guillaume Kulakowski a.k.a LLaumgui <guillaume at llaumgui dot com>
7 # Version 1.0
8 #
9 # Require : zsh, yum
10 #
11 ###############################################################################
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not,
24 # - write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 # - See http://www.gnu.org/licenses/gpl.html
27 ###############################################################################
28
29
30 # yum check-update
31 LIST=$(/usr/bin/yum check-update -d0)
32 NB_PCK=$(echo $LIST| wc -l)
33 let NB_PCK--
34
35
36 #### [ Paramètres à modifier ] ####
37 MAIL_ENTETE="[spb-box.scenario-paintball.com]"
38 MAIL_BODY_NONEW="Il n'y a pas de packet a mettre à jour."
39 MAIL_BODY_NEW="Il y a $NB_PCK packet(s) a mettre à jour."
40 MAIL_TITLE_NONEW="$MAIL_ENTETE Pas de nouvelle mise a jour"
41 MAIL_TITLE_NEW="$MAIL_ENTETE $NB_PCK mise(s) a jour"
42 #### [ / Paramètres à modifier ] ####
43
44
45 MAIL_TITLE=$MAIL_TITLE_NONEW
46 MAIL_BODY=$MAIL_BODY_NONEW
47 if [ $NB_PCK -gt 0 ]; then
48 MAIL_TITLE=$MAIL_TITLE_NEW
49 MAIL_BODY="$MAIL_BODY_NEW\n\n$LIST"
50 fi
51
52
53 echo -e $MAIL_BODY | /bin/mail -s "$MAIL_TITLE" root
Pages : 1