Christine Tran wrote:
> I need to open a file and write, but not as my UID, as another UID. I
> can finish writing and chmod the files, but I'd rather not do this.
> I'd rather open and write everything as this other UID, while running
> as myself. Is this at all possible in the UNIX world or just bonkers?
> Will it help if script runs as root?
Usually (excluding stuff like Trusted(Unix|Solaris and
Kerberos/SecureRPC environments[1]) the "root" user can use the "su"
command to switch to a different user or use "newgrp" change the current
primary group.
If you need a script to execute script code as a different uid you can
use $ su - <username> -c <command> # (e.g. $ su - otheruser -c 'chmod
a+r /home/otheruser/core/*') to execute a command as different user.
As a side-note: If you need to do complex scripting tasks which depend
on many variables you can pass "compound variables" via pipes in ksh93,
e.g. use $ print -v varname # to print the compound variable and $ read
-C varname # to read it in the other instance.
For example the following sequence will print "hello $LOGNAME" as user
"test001" when running as user root:
-- snip --
# ksh93 -c 'typeset -C a=( text="hello" number=4 ) ; print -v a' | su -
test001 -c 'typeset -C in ; read -C in ; print "${in.text}
$LOGNAME"'
Sun Microsystems Inc. SunOS 5.11 snv_110 November 2008
hello test001
-- snip --
(note that /etc/profile and ~/.profile may interfer with the piped data)
[1]=In these environments either user "root" does not exist or using
"su" to switch to a different uid does not update the process's
SecureRPC+Kerberos5 credentials (e.g. access ticket information) and the
process may not have access to data which require such credentials.
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
sysadmin-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/sysadmin-discuss