I'm running Debian 12 and Docker compose containers. Once a day, crontab should start the script, but the script should also be called manually. Could you rate my upgrade script file or recommend an alternative approach?
Requirements for the script:
- Debian 12 should be (fully) upgraded
- Docker compose container should be stopped, pulled an updated
- Docker compose should then be restarted automatically
docker system prune
should be called afterward- If a system reboot is required, the script should reboot
- The normal and error output should be to appear in console AND in an output file
- Between several steps there, should be a time waiting
#!/bin/sh
spath="/home/<...>/<folder>/"
sname="script_all.sh"
if [ $# -eq 0 ]
then
sh "${spath}${sname}" "arg1" 2>&1 | tee -a "${spath}log_$(date +%F_%T_%N).txt"
exit
fi
cd $spath || exit
docker compose down
sleep 5
sudo apt update && sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
sleep 5
if [ -f /var/run/reboot-required ]
then
at now + 2 minute -f "${spath}${sname}"
sudo reboot
else
docker compose pull
docker compose build --pull
docker compose up -d
sleep 5
docker system prune -a -f
docker system df
sleep 5
docker stats --no-stream | sort -k 2
fi
Thanks in advance.