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 >
Text File  |  2000-11-29  |  4KB  |  137 lines

  1. #!/usr/bin/perl
  2. #
  3. # mkgetlauncher: Generation du fichier /usr/local/sbin/launch_wget et 
  4. # programmation de la crontab pour son lancement automatique eventuel
  5. # Version 1.4
  6. #
  7. # This script is part of the SLIS Project initiated by the CARMI-Internet
  8. # (AcadΘmie de Grenoble - France 38).
  9. # Ce script fait partie du projet SLIS dΘmarrΘ par le CARMI-Internet
  10. # (AcadΘmie de Grenoble - France 38).
  11. #
  12. # SLIS : Serveur de communications Linux pour l'Internet Scolaire.
  13. # Copyright (C) 2000 Bruno Bzeznik
  14. #
  15. #    This program is free software; you can redistribute it and/or modify
  16. #    it under the terms of the GNU General Public License as published by
  17. #    the Free Software Foundation; either version 2 of the License, or
  18. #    (at your option) any later version.
  19. #
  20. #    This program is distributed in the hope that it will be useful,
  21. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. #    GNU General Public License for more details.
  24. #    You should have received a copy of the GNU General Public License
  25. #    along with this program (For example ./COPYING);
  26. #    if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  27. #    Cambridge, MA 02139, USA.
  28. #
  29. # Please send all comments and bug reports by electronic mail to:
  30. #   Bruno Bzeznik <Bruno@ac-grenoble.fr>
  31. # or to <slis@ac-grenoble.fr>
  32. #
  33. # Envoyez vos suggestions et reports de bugs par e-mail α
  34. #   Bruno Bzeznik <Bruno@ac-grenoble.fr>  
  35. # ou α <slis@ac-grenoble.fr>
  36. #
  37.  
  38. # Recuperation de variables SLIS
  39. do '/home/hadmin/slis.conf.pl';
  40.  
  41. # Parametres
  42. $auto_time_hour="22";
  43. $launcher="$SLIS_BINDIR/launch_wget";
  44. $htdir="/home/httpd/html/miroirs";
  45. $crontab="/usr/bin/crontab";
  46. $wget="/usr/bin/wget";
  47.  
  48. # Recuperation de l'email de l'administrateur
  49. $admin=`grep \@ $BASE/params_admin.txt`;
  50. chomp($admin);
  51. $admin =~ s/\@/\\\@/;
  52.  
  53. # Ouverture du fichier contenant les donnees pour wget
  54. open (WGET,"$BASE/wget.slis");
  55.  
  56. # Generation du lanceur
  57. open (LAUNCHER,">$launcher");
  58. print LAUNCHER "\#!/bin/bash
  59. \# Generated automaticaly by /usr/local/sbin/mkgetlauncher
  60. \# Don't edit!
  61.  
  62. . /home/hadmin/slis.conf
  63. LOGTAG=\"-t launch_wget[\$\$] -p \$LOG_FACILITY.notice\"
  64. LOG=\"/var/log/wget.log\"
  65. LANG=\"C\"
  66.  
  67. logger \$LOGTAG \"Lancement aspirations.\"
  68. date=`date`
  69. echo \"\$date : Lancement des aspirations\" >> \$LOG
  70.  
  71. \# Gestion d'un lock
  72. if [ -f /var/lock/slis.wget ]
  73. then
  74.   logger \$LOGTAG \"Deja en cours. Abandon.\"
  75.   date=`date`
  76.   echo \"\$date : Erreur, aspiration deja en cours.\" >> \$LOG
  77.   exit 1
  78. else
  79.   touch /var/lock/slis.wget
  80. fi
  81.  
  82. ";
  83.  
  84. $i=1;
  85. while (<WGET>) {
  86.   chomp();
  87.   ($url,$r,$l,$q)=split(/\t/);
  88.   if ("$url" ne "" && $r ne "" && $l ne "" && $q ne "") {
  89.     if ($r == "1") { $r="-r -l $l";} else { $r="-r -l1";}
  90.     $dir=$url;
  91.     $dir=~s?http://??;
  92.     $dir=~s?ftp://??;
  93.     print LAUNCHER "\nif [ `grep -x \"$dir\" $htdir/.miroirs | wc -l` = 0 ]\n";
  94.     print LAUNCHER "then\n";
  95.     print LAUNCHER "  echo \"$dir\" >> $htdir/.miroirs\n";
  96.     print LAUNCHER "fi\n";
  97.     print LAUNCHER "date=`date`\n";
  98.     print LAUNCHER "echo \"\$date : Debut d'aspiration $url\" >> \$LOG\n";
  99.     print LAUNCHER "$wget -nv $r -Q $q -P $htdir -N -o /var/log/wget$i $url\n";
  100.     print LAUNCHER "if [ \$? != \"0\" ]\nthen\n";
  101.     print LAUNCHER "  date=`date`\n";
  102.     print LAUNCHER "  echo \"\$date : Erreur. Voir le journal $i.\" >> \$LOG\n";
  103.     print LAUNCHER "fi\n";
  104.     print LAUNCHER "date=`date`\n";
  105.     print LAUNCHER "echo \"\$date : Fin d'aspiration $url\" >> \$LOG\n";
  106.   }
  107.   $i++;
  108. }
  109.  
  110. print LAUNCHER "\ndate=`date`\n";
  111. print LAUNCHER "echo \"\$date : Fin des aspirations\" >> \$LOG\n";
  112. print LAUNCHER "logger \$LOGTAG \"Fin aspirations.\"";
  113. print LAUNCHER "\nrm -rf /var/lock/slis.wget\n";
  114. print LAUNCHER "\nWEBMASTER=`ls -ld /home/httpd/html |awk '{print \$3}'`\n";
  115. print LAUNCHER "chown -R \$WEBMASTER /home/httpd/html/miroirs\n";
  116. close WGET;
  117. close LAUNCHER;
  118.  
  119. `chmod 755 $launcher`;
  120.  
  121. # Programmation de la crontab
  122. `/bin/rm -rf /tmp/cron.*`;
  123. $tmpext=rand();
  124. `$crontab -l |grep -v "# DO NOT EDIT THIS FILE" | \
  125.     grep -v "installed on" | \
  126.     grep -v "(Cron version --" | \
  127.     grep -v "wget" > /tmp/cron.$tmpext`;
  128. open (CRON,">>/tmp/cron.$tmpext");
  129. if (`cat $BASE/wget-auto.slis` == "1") {
  130.   print CRON "# Aspiration de sites avec wget\n";
  131.   print CRON "17 $auto_time_hour * * *    $launcher\n";
  132. }
  133. print CRON "58 3 * * *    $SLIS_BINDIR/wget_timeout\n";
  134. close CRON;
  135. `$crontab /tmp/cron.$tmpext`;
  136.  
  137.