Re: shell script how to switch users?



On Thu, Jan 04, 2007 at 06:58:53PM +0530, Rajiv Jaisankar wrote:

Hi All,
i am not sure if this is the right mailing list for asking this question. I
would appreciate any help on this.
I want to switch users using a shell script, i.e.
Say i am logged in as user1. I would like to say su - user2 in my script.
I would be performing some operations as user "user2" as part of the script
after logging in as this user.
Finally i will be exiting back to user1 shell.
How will i login as user2 through shell script?
How will i execute scripts as user2 after logging in from shell script?
Even if i am able to login as user2
any commands after "su - user2" are not executed as user2. They are executed
only as user1 when i exit the
user2 shell.

First off, please turn off HTML email. Thank you.

To answer your question, create a second script for user2 to
executed. User1 can call it with something like:

su - user2 -c "/full/path/to/user2/script"

run "info su" for more information.

--

Charles Curley /"\ ASCII Ribbon Campaign
Looking for fine software \ / Respect for open standards
and/or writing? X No HTML/RTF in email
http://www.charlescurley.com / \ No M$ Word docs in email

Key fingerprint = CE5C 6645 A45A 64E4 94C0 809C FFF6 4C48 4ECD DFDB

Attachment: pgpmU9gU2byRu.pgp
Description: PGP signature

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list

Relevant Pages

  • shell script how to switch users?
    ... I want to switch users using a shell script, ... I would like to say su - user2 in my script. ... Finally i will be exiting back to user1 shell. ... How will i login as user2 through shell script? ...
    (Fedora)
  • "su" to a non-superuser account
    ... I am trying to write a script that will su from user1 to user2. ... password prompt. ...
    (comp.sys.hp.hpux)
  • Re: [OT] change user when executing some script
    ... Both user2 and user3 can execute it. ... Even if user1 set the ... the script instead of the user that launches it? ...
    (Debian-User)
  • Re: Script-Permission
    ... script owned by root, but a non root user say user1 owns a script,which ... for user2, as user1 stores some passwords in this script. ...
    (AIX-L)
  • Re: pop-forum Re: poplog-dev A look at Poplog on the Macintosh
    ... with the poplink command. ... When trying to make pglink produce a 'sh' rather than a 'csh' shell ... script for linking and when trying to make it put unexpanded environment ... using the shell script pglibr, ...
    (comp.lang.pop)