Home > Net >  execute aws command in script with sudo
execute aws command in script with sudo

Time:10-14

I am running a bash script with sudo and have tried the below but am getting the error below using aws cp. I think the problem is that the script is looking for the config in /root which does not exist. However doesn't the -E preserve the original location? Is there an option that can be used with aws cp to pass the location of the config. Thank you :).

sudo -E bash /path/to/.sh
   - inside of this script is `aws cp`

Error

The config profile (name) could not be found


I have also tried `export` the name profile and `source` the path to the `config`

CodePudding user response:

You can use the original user like :

sudo -u $SUDO_USER aws cp ...

CodePudding user response:

You could also run the script using source instead of bash -- using source will cause the script to run in the same shell as your open terminal window, which will keep the same env together (such as user) - though honestly, @Philippe answer is the better, more correct one.

  • Related