I learned to use a computer with DOS so I am trying to approximate a batch/.bat file to run all the updates to my system and create a log file of the outcome.
#!/bin/bash
#update system in one step
cd ~
date > aupdate.log
echo Launching updates...
echo Beginning apt update
sudo apt update >> aupdate.log
sudo apt upgrade -y >> aupdate.log
echo Completing apt autoremove process
sudo apt autoremove -y >> aupdate.log
echo Beginning snap update
sudo snap refresh >> aupdate.log
echo Beginning flatpak update
flatpak update -y >> aupdate.log
echo Updates complete. Review aupdate.log for details.
Am I on the right track? So far I have two problems I need to resolve.
- No log file is being created
- How do I suppress the warning about redirecting output when running apt > filename (EDIT: See below)
Edit: This is the result when I run the script:
Launching updates...
Beginning apt updates
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Completing apt autoremove process
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Beginning snap update
All snaps up to date.
Beginning flatpak update
Updates complete. Review aupdate.log for details.
EDIT: Based on some early feedback from the comments, I changed the script
#!/bin/bash
#update system in one step. Vers 1.1
date > ~/aupdate.log
echo Beginning update...
echo Beginning apt-get updates
apt-get update >> ~/aupdate.log
apt-get upgrade -y >> ~/aupdate.log
echo Completing apt autoremove process
apt-get autoremove -y >> ~/aupdate.log
echo Beginning snap update
snap refresh >> ~/aupdate.log 2>/dev/null
echo Beginning flatpak update
flatpak update -y >> ~/aupdate.log
echo Updates complete. Review aupdate.log for details.
Switching to apt-get
resolved the warning and using 2>/dev/null
with the snap
line suppressed a snap output I just noticed. I also removed sudo
from the lines because I run the script as su. However there's still no log file
EDIT: This is the result when I run the script now as well as ls
after.
eddie@mrpbell5:~$ sudo ./aupdate.sh
Beginning update...
Beginning apt-get updates
Completing apt autoremove process
Beginning snap update
Beginning flatpak update
Updates complete. Review aupdate.log for details.
eddie@mrpbell5:~$ ls ~ | grep log
eddie@mrpbell5:~$ ls -a
. .bash_history .cache .config Downloads .local Music .profile src .surfshark Videos
.. .bash_logout .cert Desktop .gnome move Pictures Public .ssh Templates .wget-hsts
aupdate.sh .bashrc CiscoSpark Documents .gnupg .mozilla .pki snap .sudo_as_admin_successful .var .zoom
apt
warning is to useapt-get
instead ofapt
. Alternatively, you can redirectapt
's stderr to/dev/null
usingsudo apt update >> aupdate.log 2>/dev/null
. – BeastOfCaerbannog Apr 28 '22 at 20:06cd ~
. Just use the path to your log file, for examplesudo apt update >> /path/to/aupdate.log
, or, if you want it in your home,sudo apt update >> ~/aupdate.log
. – BeastOfCaerbannog Apr 28 '22 at 20:11sudo ./aupdate.sh
it wil then run each line as su even without specifyingsudo
for that line? – EHJ Apr 28 '22 at 20:12apt-get
rather thanapt
. Readman apt-get
. Also, you're only redirecting STDOUT, not STDERR. Readman bash
. Where willsudo
get its authentication from when the script is run? You're resettlingaupdate.log
every time. Linux isn't DOS. – waltinator Apr 28 '22 at 20:14dir /p/l/w
is always giving me an error! ;-) – EHJ Apr 28 '22 at 20:19