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.

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.