home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ac-grenoble.fr
/
2015.02.ftp.ac-grenoble.fr.tar
/
ftp.ac-grenoble.fr
/
pub
/
slis
/
updates_rsync
/
mkwgetlauncher
< prev
next >
Wrap
Text File
|
2000-11-29
|
4KB
|
137 lines
#!/usr/bin/perl
#
# mkgetlauncher: Generation du fichier /usr/local/sbin/launch_wget et
# programmation de la crontab pour son lancement automatique eventuel
# Version 1.4
#
# This script is part of the SLIS Project initiated by the CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
# Ce script fait partie du projet SLIS dΘmarrΘ par le CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
#
# SLIS : Serveur de communications Linux pour l'Internet Scolaire.
# Copyright (C) 2000 Bruno Bzeznik
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program (For example ./COPYING);
# if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
#
# Please send all comments and bug reports by electronic mail to:
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# or to <slis@ac-grenoble.fr>
#
# Envoyez vos suggestions et reports de bugs par e-mail α
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# ou α <slis@ac-grenoble.fr>
#
# Recuperation de variables SLIS
do '/home/hadmin/slis.conf.pl';
# Parametres
$auto_time_hour="22";
$launcher="$SLIS_BINDIR/launch_wget";
$htdir="/home/httpd/html/miroirs";
$crontab="/usr/bin/crontab";
$wget="/usr/bin/wget";
# Recuperation de l'email de l'administrateur
$admin=`grep \@ $BASE/params_admin.txt`;
chomp($admin);
$admin =~ s/\@/\\\@/;
# Ouverture du fichier contenant les donnees pour wget
open (WGET,"$BASE/wget.slis");
# Generation du lanceur
open (LAUNCHER,">$launcher");
print LAUNCHER "\#!/bin/bash
\# Generated automaticaly by /usr/local/sbin/mkgetlauncher
\# Don't edit!
. /home/hadmin/slis.conf
LOGTAG=\"-t launch_wget[\$\$] -p \$LOG_FACILITY.notice\"
LOG=\"/var/log/wget.log\"
LANG=\"C\"
logger \$LOGTAG \"Lancement aspirations.\"
date=`date`
echo \"\$date : Lancement des aspirations\" >> \$LOG
\# Gestion d'un lock
if [ -f /var/lock/slis.wget ]
then
logger \$LOGTAG \"Deja en cours. Abandon.\"
date=`date`
echo \"\$date : Erreur, aspiration deja en cours.\" >> \$LOG
exit 1
else
touch /var/lock/slis.wget
fi
";
$i=1;
while (<WGET>) {
chomp();
($url,$r,$l,$q)=split(/\t/);
if ("$url" ne "" && $r ne "" && $l ne "" && $q ne "") {
if ($r == "1") { $r="-r -l $l";} else { $r="-r -l1";}
$dir=$url;
$dir=~s?http://??;
$dir=~s?ftp://??;
print LAUNCHER "\nif [ `grep -x \"$dir\" $htdir/.miroirs | wc -l` = 0 ]\n";
print LAUNCHER "then\n";
print LAUNCHER " echo \"$dir\" >> $htdir/.miroirs\n";
print LAUNCHER "fi\n";
print LAUNCHER "date=`date`\n";
print LAUNCHER "echo \"\$date : Debut d'aspiration $url\" >> \$LOG\n";
print LAUNCHER "$wget -nv $r -Q $q -P $htdir -N -o /var/log/wget$i $url\n";
print LAUNCHER "if [ \$? != \"0\" ]\nthen\n";
print LAUNCHER " date=`date`\n";
print LAUNCHER " echo \"\$date : Erreur. Voir le journal $i.\" >> \$LOG\n";
print LAUNCHER "fi\n";
print LAUNCHER "date=`date`\n";
print LAUNCHER "echo \"\$date : Fin d'aspiration $url\" >> \$LOG\n";
}
$i++;
}
print LAUNCHER "\ndate=`date`\n";
print LAUNCHER "echo \"\$date : Fin des aspirations\" >> \$LOG\n";
print LAUNCHER "logger \$LOGTAG \"Fin aspirations.\"";
print LAUNCHER "\nrm -rf /var/lock/slis.wget\n";
print LAUNCHER "\nWEBMASTER=`ls -ld /home/httpd/html |awk '{print \$3}'`\n";
print LAUNCHER "chown -R \$WEBMASTER /home/httpd/html/miroirs\n";
close WGET;
close LAUNCHER;
`chmod 755 $launcher`;
# Programmation de la crontab
`/bin/rm -rf /tmp/cron.*`;
$tmpext=rand();
`$crontab -l |grep -v "# DO NOT EDIT THIS FILE" | \
grep -v "installed on" | \
grep -v "(Cron version --" | \
grep -v "wget" > /tmp/cron.$tmpext`;
open (CRON,">>/tmp/cron.$tmpext");
if (`cat $BASE/wget-auto.slis` == "1") {
print CRON "# Aspiration de sites avec wget\n";
print CRON "17 $auto_time_hour * * * $launcher\n";
}
print CRON "58 3 * * * $SLIS_BINDIR/wget_timeout\n";
close CRON;
`$crontab /tmp/cron.$tmpext`;