0

I have a simple bash script like this:

#!/usr/bin/env bash

sudo ./some_other_script_01
sudo ./some_other_script_02

When I execute this script, I always see the password prompt, as usual:

[sudo] password for user: 

However sometimes, inexplicably, before I have typed my password, ./some_other_script_01 starts getting executed (presumably without root permissions). This happens even though it did prompt me for a password (which I didn't yet provide).

Currently, when this happens, I have to kill the scripts and start again (so that they get executed with root privileges).

  • 1
    Is sudo configured with passwd_timeout set to some too small value in the sudoers file? – Kusalananda Mar 7 at 21:56
  • If you want to force sudo to ask for a password, use the -k option. Check your man page for details. – glenn jackman Mar 7 at 22:18
2

Sudo once is enough, just start the wrapper.sh with sudo. Check if you have root permission in the script no more sudo calls needed.

sudo ./wrapper.sh

wrapper.sh:

#!/usr/bin/env bash

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

./some_other_script_01
./some_other_script_02
  • 1
    Thank you. I've marked this as the answer because it's the right thing to do, but it still doesn't solve my mystery. I will keep investigating. – logidelic Mar 8 at 14:24

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.