| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
|
| Hi all, i need to change user in root script and launch commands. For example: #!/bin/bash su - john (in john environment) cd scripts go.sh (with john variables) exit in this case, the user became murex but next command after "su - john" goes in root user how can i do? i tried with: #!/bin/bash su - john <<- END (in john environment) cd scripts go.sh (with john variables) exit END but it doesn't work thanks |
|
#2
|
| Patrick > in this case, the user became murex but next command after "su - john" > goes in root user You need to review the 'su' manpage... in particular, the '-c' argument, which acts much like -c when supplied to a shell. su - john -c '/usr/bin/env' However, be aware that it might not pick up environment settings from the user's .profile and the like. (It probably will, but I've seen cases where it didn't.) Be careful how much you assume. -- Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/ |
|
#3
|
| Patrick schreef: > Hi all, i need to change user in root script and launch commands. For > example: > > #!/bin/bash > su - john > (in john environment) > cd scripts > go.sh (with john variables) > exit > > in this case, the user became murex but next command after "su - john" > goes in root user > > how can i do? i tried with: > #!/bin/bash > su - john <<- END > (in john environment) > cd scripts > go.sh (with john variables) > exit > END > but it doesn't work > > thanks You can do this: su - john -c "/scripts/go.sh" |
|
#4
|
| Patrick wrote: > #!/bin/bash > su - john > (in john environment) > cd scripts > go.sh (with john variables) > exit man su: To execute command with the temporary environment and per- missions of user bin, type: example% su - bin -c "command args" or su - user -c "cd scripts; ./go.sh" |
![]() |
| Thread Tools | |
| Display Modes | |