You are not logged in.

#1 2022-01-04 03:08:42

katarok
Member
Registered: 2020-05-24
Posts: 33

Why doesn't Bash wait for pacman to finish updating?

I made this small Bash script to automate system upgrades.

#! /bin/bash

read -s -p "Superuser Authentication: " sudoPW

export HISTIGNORE='*sudo -S*'
(
echo 'Updating AUR Packages..'
paru -Sua
echo 'Updating AUR Done'
echo 'Updating Arch Packages..'
echo $sudoPW | sudo -S -k pacman -Syu
echo 'Updating Arch Packages Done'
) 2>&1 | tee -a ~/update$(date +"%Y-%m-%d_%T").log
shutdown

but for some reason the system always shutdowns before the actual update finishes. Why is that? And how can I prevent it?

Offline

#2 2022-01-04 04:54:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 26,197
Website

Re: Why doesn't Bash wait for pacman to finish updating?

katarok wrote:

I made this small Bash script to automate system upgrades.

That's a bad idea ...

katarok wrote:

read -s -p "Superuser Authentication: " sudoPW

And that's a far far worse idea!  Use `sudo -v` that's what it's for.

katarok wrote:

Why is that?

You direct all the output to a log ... start there.

I'd guess paru at least is failing as it would need root access to install any built packages, but no password is provided to it.

Last edited by Trilby (2022-01-04 05:09:47)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-01-04 12:53:14

katarok
Member
Registered: 2020-05-24
Posts: 33

Re: Why doesn't Bash wait for pacman to finish updating?

Trilby wrote:

Use `sudo -v` that's what it's for.

Doesn't 'sudo -v' only work for like a couple of minutes?

Trilby wrote:

You direct all the output to a log ... start there.

The reason the log exists in the first place is because I saw that the system shut down before the update could finish so I needed to see what happened before the shutdown. It didn't really help, but I decided to keep it because generally a log seems useful.

Tribly wrote:

I'd guess paru at least is failing as it would need root access to install any built packages, but no password is provided to it.

I don't automate Paru, Hence it is first.

Offline

#4 2022-01-04 13:43:23

seth
Member
Registered: 2012-09-03
Posts: 26,570

Re: Why doesn't Bash wait for pacman to finish updating?

Doesn't 'sudo -v' only work for like a couple of minutes?

You can actually control that but while I agree w/ Trilby that reading the password into a variable and echoing it around in an unattended process is … objectable, it's not your problem.

I don't automate Paru, Hence it is first.

I'm not sure what's that supposed to say but
"paru -Sua" will require root privileges so unless it elevates itself, you need to sudo it.

so I needed to see what happened before the shutdown. It didn't really help

Why not? You might want to share it since it'll gt others a hint about what's going on there.

A massive problem could be that "pacman -Syu" is typically going to require some stdin what may or not be provided by the context of your script and rather not in that subshell.

Offline

#5 2022-01-17 06:47:23

katarok
Member
Registered: 2020-05-24
Posts: 33

Re: Why doesn't Bash wait for pacman to finish updating?

First I would like to apologize for a delayed response, I was caught up in a project and I kinda forgot about my thread as well as my struggle with making the script work. My bad.
Secondly, thank you for your interest in my script smile

seth wrote:

I don't automate Paru, Hence it is first.

I'm not sure what's that supposed to say but
"paru -Sua" will require root privileges so unless it elevates itself, you need to sudo it.

Well I didn't find a way to automate paru approval over the few AURs I have so I still have to exit vim and say yes so I put it first to get done

seth wrote:

so I needed to see what happened before the shutdown. It didn't really help

Why not? You might want to share it since it'll gt others a hint about what's going on there.

Well the log showed that at some random point while it was downloading packages it shutdown. This happened every time with different packages. So I don't quite get the problem...

Offline

#6 2022-01-17 07:48:04

seth
Member
Registered: 2012-09-03
Posts: 26,570

Re: Why doesn't Bash wait for pacman to finish updating?

What context is that script run and does

paru -Sua; sudo pacman -Syu && shutdown

in an interactive shell "work"?

Also, how does the log show that *it* shutdown?
Tried a leadign "set -x"? Is maybe something entirely different shutting down the system? (hence "context"…)

Offline

Board footer

Powered by FluxBB