I've been trying to run my bash script, but the terminal starts acting up. Even after changing the permissions, it's still not working right. Could you help me figure out what's going wrong? Here's what my script looks like:
```bash
#!/bin/bash
echo "Updating..."
set -e
LOG_FILE="/var/log/apt/history.log"
sudo apt update >> "$LOG_FILE" 2>&1
sudo apt upgrade -y >> "$LOG_FILE" 2>&1
sudo apt autoremove -y >> "$LOG_FILE" 2>&1
sudo apt clean -y >> "$LOG_FILE" 2>&1
EXIT_STATUS=$?
if [ $EXIT_STATUS -eq 0 ]; then
echo "Done!" >> "$LOG_FILE"
else
echo "An error occurred..." >> "$LOG_FILE"
fi
```
2 Answers
You might want to check this out with a tool like ShellCheck! It looks like there are a few issues with your script regarding how you’re redirecting the output and using `sudo`. Basically, running `sudo` doesn't affect redirects, so you should consider using `| sudo tee -a "$LOG_FILE"` instead.
Hey, you're writing to the apt history log, which is not a good idea. That log is meant for apt's own processes. You might want to create a new log file for your script instead. Also, have you looked into using `unattended-upgrades`? It could handle updates automatically for you!
Totally agree! Unattended-upgrades can definitely simplify things for you.