ajout tache cron auto-update
This commit is contained in:
33
Integration_domain/apt-update.sh
Normal file
33
Integration_domain/apt-update.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
#=======================================================================
|
||||
# FILE: ~apt-update.sh
|
||||
# USAGE: ./~apt-update.sh
|
||||
# DESCRIPTION: script permettant la mise a jour masquée des paquets du poste
|
||||
#
|
||||
# OPTIONS: ---
|
||||
# REQUIREMENTS: ---
|
||||
# BUGS: ---
|
||||
# NOTES: ---
|
||||
# AUTHOR: Maxime Tertrais
|
||||
# COMPANY: Operis
|
||||
# CREATED: 18/10/2024
|
||||
# REVISION: ---
|
||||
#=======================================================================
|
||||
##Définition des variables
|
||||
log_file="/var/log/apt-logs.log"
|
||||
#=======================================================================
|
||||
##Définition des fonctions
|
||||
|
||||
#=======================================================================
|
||||
##Script
|
||||
main() (
|
||||
{
|
||||
echo "Mise à jour système: $(date)"
|
||||
apt update -y
|
||||
apt upgrade -y
|
||||
apt autoremove -y
|
||||
echo '---------------------------------------'
|
||||
} >> $log_file 2>&1
|
||||
)
|
||||
|
||||
main "$@"
|
||||
@@ -26,6 +26,10 @@ domain="operis.champlan"
|
||||
Allowed_GG=(GRP_ADM_POSTE GRP_ADM_DOM GDL_Orvault GDL_LaRéunion GDL_Grenoble GDL_Champlan GDL_Bordeaux)
|
||||
local_admin="operis"
|
||||
GG_admin="grp_adm_poste"
|
||||
cron_file="/etc/crontab"
|
||||
cron_job="0 9 * * * bash /root/apt-update.sh"
|
||||
script_auto_update_src="$folder/Integration_domain/apt-update.sh"
|
||||
script_auto_update_dst="/root/apt-update.sh"
|
||||
#=======================================================================
|
||||
##Définition des fonctions
|
||||
func_dependances(){
|
||||
@@ -151,6 +155,20 @@ func_root(){
|
||||
fi
|
||||
}
|
||||
|
||||
func_cron(){
|
||||
sudo crontab -l | grep -F "$cron_job" > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Le job cron existe déjà dans la crontab de root."
|
||||
else
|
||||
# tranfert du script d'update dans le dossier /root/
|
||||
mv $script_auto_update_src $script_auto_update_dst
|
||||
chown root:root $script_auto_update_dst
|
||||
chmod +x $script_auto_update_dst
|
||||
# Ajouter le nouveau job cron
|
||||
(sudo crontab -l; echo "$cron_job") | sudo crontab -
|
||||
fi
|
||||
}
|
||||
|
||||
#=======================================================================
|
||||
###Script
|
||||
|
||||
|
||||
Reference in New Issue
Block a user