0

I have a script to setup a machine that need to change to another user. Unfortunately, I get a "permission denied" after the su command.

#!/bin/bash
# script executed from /home/foo/
touch hi_foo
cd /home/bar
sudo bar
touch hi_bar <-- permission denied

Any idea of a workaround? My script works well if I copy and paste it in the command line.

I am running Ubuntu 14.04

user37220
  • 225
  • 2
  • 5
  • 8

1 Answers1

0

try:

#!/bin/bash
# script executed from /home/foo/
touch hi_foo
cd /home/bar
su bar touch hi_bar

you need to run your script with sudo so the process running your script will have sufficient rights to run su bar command

Henrik Pingel
  • 9,380
  • 2
  • 28
  • 39