0

Hi ,
I want to run a shell script which is present in another user's id after switching it to that user in the same script. but it is not taking it. I m using the su command for that.

su - user1 -c "./${HOME}/script1.sh"

it just says invalid command. Please help. I need it urgently.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by nikita.
0

Hi ,
I want to run a shell script which is present in another user's id after switching it to that user in the same script. but it is not taking it. I m using the su command for that.

su - user1 -c "./${HOME}/script1.sh"

it just says invalid command. Please help. I need it urgently.

1. $HOME is expanded in the current shell, i.e. before you have changed users.

2. $HOME is not a subdirectory of the current directory; which is what you are saying when you use ./${HOME}/

3. In scripts, use 'sudo -u user1 ...'.

4. Don't put scripts in users' home directories; put them in a directory in your PATH

0

is it possible if we want to run a number of commands after switching the user and remain in that shell only.

su - newuser -c"command"

allows only one command to run and in that also the home dir is of the old user.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.