1

I have an Arch Linux machine with Openbox, and I want to run an update on my autostart script (bash) - so I added the following command to my autostart: rxvt -e sudo pacman -Syu & (i.e. open rxvt terminal and run the standard update command for Archlinux's package manager, pacman).

However, sometimes the database is locked by another pacman process, and then the command fails and just closes rxvt without doing anything - so I wanted to remove the lock first by using rxvt -e sudo rm /var/lib/pacman/db.lck && sudo pacman -Syu & (remove the lock on pacman and then update). This doesn't work as actually only the first command is executed in the rxvt instance.

Is there any way to get it right (running two commands on a terminal opened with a -e flag)? I know I could open two separate terminals, each executing one command, but that would be really messy in my opinion. Alternatively, if there's another simpler way to make sure the lock isn't there, it's also okay by me (although I prefer it on the same terminal so I can see the output of the rm clearly)

  • Or maybe only run pacman if the lock file does NOT exist? – Jeff Schaller Aug 9 '16 at 20:35
1

Use quotes to make this a single command:

rxvt -e  "sudo rm /var/lib/pacman/db.lck && sudo pacman -Syu" &

Some terminals need that to be wrapped in a shell command, e.g.,

rxvt -e sh -c "sudo rm -f /var/lib/pacman/db.lck && sudo pacman -Syu" &

The -f flag ignores the file if it's not there and avoids an error

  • Thanks, I did try the first command before asking, but only the second did the trick. Only I had to change it to rm -f in case the file isn't there (so it doesn't throw me out) – Odedi Aug 9 '16 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.