Mise à jour automatique des scripts : Différence entre versions
De wikiGite
| Ligne 8 : | Ligne 8 : | ||
Puis créer juste les noms des scripts pour une première mise à jour. Ex : | Puis créer juste les noms des scripts pour une première mise à jour. Ex : | ||
touch /opt/systools/ossec-local-rules.sh | touch /opt/systools/ossec-local-rules.sh | ||
| + | touch /opt/systools/nmap_ossec.sh | ||
touch /opt/systools/dumpmysql.sh | touch /opt/systools/dumpmysql.sh | ||
touch /opt/systools/check_services.sh | touch /opt/systools/check_services.sh | ||
touch /opt/systools/monit-stop.sh # (obsolete - voir plus bas) | touch /opt/systools/monit-stop.sh # (obsolete - voir plus bas) | ||
touch /opt/systools/monit-start.sh | touch /opt/systools/monit-start.sh | ||
| − | |||
Sur une BlueOnyx : | Sur une BlueOnyx : | ||
touch /opt/systools/cmuBackup.sh | touch /opt/systools/cmuBackup.sh | ||
| Ligne 27 : | Ligne 27 : | ||
Et sur une BlueOnyx : | Et sur une BlueOnyx : | ||
ln -s /opt/systools/cmuBackup.sh cmuBackup | ln -s /opt/systools/cmuBackup.sh cmuBackup | ||
| + | Si nmap est ajouté à Ossec, prévoir une rotation du log | ||
| + | echo "/var/log/nmap-out.log {" > /etc/logrotate.d/nmap_ossec | ||
| + | echo " weekly" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " rotate 5" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " compress" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " missingok" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " notifempty" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " create 0640 root root" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " sharedscripts" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " postrotate" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " /etc/cron.hourly/nmap_ossec.sh" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo " endscript" >> /etc/logrotate.d/nmap_ossec | ||
| + | echo "}" >> /etc/logrotate.d/nmap_ossec | ||
Planifier aussi maj_scripts par un lien dans /etc/cron.daily, En tête de liste pour qu'il se lance avant les autres scripts, et le lancer une première fois (il se met à jour lui-même) et une seconde (il met à jour les autres scripts). | Planifier aussi maj_scripts par un lien dans /etc/cron.daily, En tête de liste pour qu'il se lance avant les autres scripts, et le lancer une première fois (il se met à jour lui-même) et une seconde (il met à jour les autres scripts). | ||
cd /etc/cron.daily | cd /etc/cron.daily | ||
Version actuelle datée du 25 juillet 2013 à 09:48
créer /opt/systools/maj_scripts.sh (changer le mail de l'admin !)
mkdir /opt/systools chmod 700 /opt/systools cd /opt/systools wget http://www.systea.net/public/MaJ/maj_scripts.sh.maj -O maj_scripts.sh
Ne pas oublier
chmod 700 /opt/systools/maj_scripts.sh
Puis créer juste les noms des scripts pour une première mise à jour. Ex :
touch /opt/systools/ossec-local-rules.sh touch /opt/systools/nmap_ossec.sh touch /opt/systools/dumpmysql.sh touch /opt/systools/check_services.sh touch /opt/systools/monit-stop.sh # (obsolete - voir plus bas) touch /opt/systools/monit-start.sh
Sur une BlueOnyx :
touch /opt/systools/cmuBackup.sh
Et planifier tout de suite ces scripts pour ne pas oublier !
cd /etc/cron.hourly ln -s /opt/systools/check_services.sh check_services ln -s /opt/systools/nmap_ossec.sh nmap_ossec cd /etc/cron.daily # ln -s /opt/systools/monit-stop.sh 00monit-stop.sh echo "00 0 * * * /opt/systools/monit-stop.sh" > /etc/cron.d/monit-stop ln -s /opt/systools/monit-start.sh zzmonit-start.sh ln -s /opt/systools/ossec-local-rules.sh ossec-local-rules #ln -s /opt/systools/dumpmysql.sh dumpmysql #plus nécessaire si dump par rdiff-backup
Et sur une BlueOnyx :
ln -s /opt/systools/cmuBackup.sh cmuBackup
Si nmap est ajouté à Ossec, prévoir une rotation du log
echo "/var/log/nmap-out.log {" > /etc/logrotate.d/nmap_ossec
echo " weekly" >> /etc/logrotate.d/nmap_ossec
echo " rotate 5" >> /etc/logrotate.d/nmap_ossec
echo " compress" >> /etc/logrotate.d/nmap_ossec
echo " missingok" >> /etc/logrotate.d/nmap_ossec
echo " notifempty" >> /etc/logrotate.d/nmap_ossec
echo " create 0640 root root" >> /etc/logrotate.d/nmap_ossec
echo " sharedscripts" >> /etc/logrotate.d/nmap_ossec
echo " postrotate" >> /etc/logrotate.d/nmap_ossec
echo " /etc/cron.hourly/nmap_ossec.sh" >> /etc/logrotate.d/nmap_ossec
echo " endscript" >> /etc/logrotate.d/nmap_ossec
echo "}" >> /etc/logrotate.d/nmap_ossec
Planifier aussi maj_scripts par un lien dans /etc/cron.daily, En tête de liste pour qu'il se lance avant les autres scripts, et le lancer une première fois (il se met à jour lui-même) et une seconde (il met à jour les autres scripts).
cd /etc/cron.daily ln -s /opt/systools/maj_scripts.sh 0maj_scripts ./0maj_scripts ./0maj_scripts cd /opt/systools/ ls -l
maj_scripts.sh
Pour information
#!/bin/bash
# FSo 2010-03
# V1.1
# Automatically update system scripts
# First update itself
# Then update all ".sh" script in directory, from a centralized place
SCRIPTS_DIR=/opt/systools
UPDATE_SERVER=http://www.systea.net/public/MaJ
CHANGED=0
REPORT=""
REPORT_EMAIL=<Mail de l'admin>
# Verify if standard directory exist
if [ -d $SCRIPTS_DIR ]
then
# Get files
cd $SCRIPTS_DIR
# script itself : if updated, it overwrite itself and exits :
# don't know what it could do after being overwrited, so tomorrow is another day
SCR=maj_scripts.sh
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."
exit 0
else
rm -f $SCR.maj*
fi
fi
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."
REPORT="$(echo -e "$SCR has changed.\n") $REPORT"
CHANGED=1
else
rm -f $SCR.maj*
fi
fi
done
if [ $CHANGED -eq 1 ]
then
(
echo "Subject: [scripts_update] $(hostname) Daily run"
echo $REPORT
) | /usr/sbin/sendmail $REPORT_EMAIL
fi
fi
