0

I'm writing a bash script here to install docker and send all outputs to the logs.txt file. But i still get errors such as the one below displayed on the terminal, what I'm i doing wrong here to get these errors?

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
    if [[ `command -v apt-get` ]]; then
    echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Getting requirements....."
        sleep 1;
        sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release >> logs.txt
    echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Adding Docker’s official GPG key........"
        sleep 1;
        curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Installing Docker......."
        sleep 1;
        sudo apt-get install -y docker-ce docker-ce-cli containerd.io >> logs.txt
    echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Docker version........"
        sleep 1;
        docker --version | head -n1
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
badman
  • 319
  • 1
  • 12
  • 3
    You're sending standard output to the log file, not standard error. – Barmar Jul 22 '21 at 22:53
  • 2
    You can send error output to the file as well by appending `2>&1` to each command. – John Bollinger Jul 22 '21 at 22:55
  • @Barmar same error prints when i use "> logs.txt 2>&1" – badman Jul 22 '21 at 22:56
  • Put `set -x` at the beginning of the script so you can see which command is doing this. – Barmar Jul 22 '21 at 22:59
  • If `2>&1` doesn't redirect the errors, it must be writing them directly to `/dev/tty` for some reason. – Barmar Jul 22 '21 at 23:00
  • That error is related to apt-get. You can only run one at a time, and each execution tries to obtain the lock, hence the error you see. Add a `2>> logs.txt` to both apt-get lines to capture the errors. – Nic3500 Jul 23 '21 at 00:41

0 Answers0