Outils personnels

Mise à jour automatique des scripts

De wikiGite

Révision datée du 25 mars 2010 à 09:00 par Frank (discussion | contributions) (Page créée avec « Dans /opt/systools, créer maj_scripts.sh #!/bin/bash # FSo 2010-03 # V1.0 # Update system scripts SCRIPTS_DIR=/opt/systools UPDATE_SERVER=http://www.systea.net/publ... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

Dans /opt/systools, créer maj_scripts.sh

#!/bin/bash
# FSo 2010-03
# V1.0
# Update system scripts 

SCRIPTS_DIR=/opt/systools
UPDATE_SERVER=http://www.systea.net/public/MaJ
CHANGED=0
REPORT_EMAIL=fsoyer@systea.net

# Verify if standard directory exist
if [ -d $SCRIPTS_DIR ]
then
  # Get files
  cd $SCRIPTS_DIR
  for SCR in $(ls *.sh)
  do
    wget -q $UPDATE_SERVER/$SCR.maj > /dev/null 2>&1
    # If exists and download is ok
    if [ $? -eq 0 ]
    then
      cmp $SCR.maj $SCR > /dev/null 2>&1
      # If downloaded file differs from local file, install it
      if [ $? -gt 0 ]
      then
        # If there is no backup copy of file
        if [ ! -f $SCR.old ]
        then
          cp $SCR $SCR.old
        fi
        mv $SCR.maj $SCR
        chmod 700 $SCR
        logger -t update_scripts "$SCR has changed."
        CHANGED=1
      else
        rm -f $SCR.maj*
      fi
    fi
  done
  if [ $CHANGED -eq 1 ]
  then
    (
     echo "Subject: [scripts_update] $(hostname) Daily run"
     echo ""
     ) | /usr/sbin/sendmail $REPORT_EMAIL
  fi
fi

Puis créer juste les noms des scripts pour une première mise à jour. Ex :

touch ossec-local-rules.sh
touch dumpmysql.sh

Planifier maj_scripts par un lien dans /etc/cron.daily, et le lancer une première fois manuellement.