From: "Jackie R. Miller" <jmiller () whitworth ! edu>
To: tru64-unix-managers
Subject: Summary: su - <username> -c "script"
Date: Fri, 23 Feb 2001 23:18:59 +0000 [thread overview]
Message-ID: <98297052104596.tru64-unix-managers.marc@archive.invalid> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: multipart/mixed; boundary="------_=_NextPart_001_01C09DEF.00908630", Size: 13303 bytes --]
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C09DEF.00908630
Content-Type: text/plain;
charset="iso-8859-1"
Problem: su - <username> -c "script" not working and getting -c option not
recognized error.
Thanks to everyone for the quick and very large response. I have pasted
below a representative sample of the replies received with the most common
reply being that it works fine on their system.
In my case I was using the command in a script which was calling it via an
"at" command and I should have added that information to the initial
request. One of the replies suggested that the -c option was meant for cron
and that caused me to look at the "at" environment. I think that was the
problem because by calling it directly instead of via "at" it now works and
the -c option error is not displayed. Still have not succeeded in getting
it to work via "at" but have other fish to fry.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
you need a different format of the 'su' command between v4 and v5 ... this
is what I use:
# test for OS version number
ver=`uname -a | awk ' { print $3 } ' | cut -d'.' -f1`
if [ "${ver}" = "V5" ]
then
V5=" -c "
else
V5=""
fi
su dbadmin ${V5} "/usr/bin/rsh $HOST $COMMAND"
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
there is indeed no man page in 4.0d, but in my 4.0d system (on a 4100, too,
with Patch Kit 4) the following command works without problems:
su - steffi -c do_something
where do_something is a script lying in my home directory.
Attention: the first "-" has two blanks around it, the "-c" is written - as
usually - without a blank between.
And voila: the man page from 3.2g
su(1) su(1)
NAME
su - Substitutes user ID temporarily
SYNOPSIS
su [-f] | [-c command] | [-] [user]
FLAGS
-c command
Executes the specified command in the user's shell.
-f Prevents the user's shell initialization file from being executed
by
passing the -f option to the user's shell, thus making su start up
fas-
ter.
- Simulates a full login by executing the commands in either
the .cshrc
and .login files for csh or the .profile file for sh and ksh and
by
setting the current working directory to the user's home directory.
>>>>>>>>>>>>>>>>>>>>>>
I tried several variations on my system (4.0D with patch kit 7 installed)
and su - username -c script worked on all except one. That was when the
script did not have execute permission. Are you sure the execute bits are
set? Does the script have a "#!/path/to/interpreter" comment at the top?
BTW, to answer one question, su passes the -c to the shell invoked by the
su - username
>>>>>>>>>>>>>>>>>>>>>>>>
The -c option does work on v4.0d.
In my KSH script that starts and stop my Oracle Apps and DBMS I'm using the
command :
/usr/bin/su - ${DBUSER} -c "ORACLE_SID=$lSID ; export ORACLE_SID ; svrmgrl"
>>$LOGFILE 2>&1
With the env variables assigned appropriately it works flawlessly.
The script may be the name of a script to execute or any other valid command
line. Keep in mind that the environment that the script will execute under
is that of the user that you are su'ing to, so that user's path, etc. must
be set correctly.
>>>>>>>>>>>>>>
Have you tried sudo? It allows a system administrator to give some users the
right to run some commands as root or as another user. I believe it allow
root to run commands as another user, also. Look at the sudo web page at:
http://www.courtesan.com/sudo/
>>>>>>>>>>>>>>>>>>>.
I suggest the su - <username> -c "script" syntax is meant for crontab; ie.
such that cron runs the script instead of a user doing it interactively.
>>>>>>>>>>>>>>>>>>
Try using rsh instead.
# rsh <node> -l <user> <command>
You will need a ".rhosts" file on the remote node though. More information
from "man rsh". Hope this helps.
>>>>>>>>>>>>>>>>>>>>
Jackie R. Miller
Director, Information Systems
Whitworth College
509 777-4486
------_=_NextPart_001_01C09DEF.00908630
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>Summary: su - <username> -c "script"</TITLE>
</HEAD>
<BODY>
<P><FONT FACE=3D"Lucida Sans">Problem: su - <username> -c =
"script" not working and getting -c option not recognized =
error.</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">Thanks to everyone for the quick and very =
large response. I have pasted below a representative sample of =
the replies received with the most common reply being that it works =
fine on their system.</FONT></P>
<P><FONT FACE=3D"Lucida Sans">In my case I was using the command in a =
script which was calling it via an "at" command and I should =
have added that information to the initial request. One of the =
replies suggested that the -c option was meant for cron and that caused =
me to look at the "at" environment. I think that was =
the problem because by calling it directly instead of via =
"at" it now works and the -c option error is not =
displayed. Still have not succeeded in getting it to work via =
"at" but have other fish to fry.</FONT></P>
<P><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>>>>&g=
t;>>>>>>>>>>>>>.</FONT>
<BR><FONT FACE=3D"Lucida Sans">you need a different format of the 'su' =
command between v4 and v5 ... this is what I use:</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans"># test for OS version number</FONT>
<BR><FONT FACE=3D"Lucida Sans">ver=3D`uname -a | awk ' { print $3 } ' | =
cut -d'.' -f1`</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">if [ "${ver}" =3D =
"V5" ]</FONT>
<BR><FONT FACE=3D"Lucida Sans">then</FONT>
<BR><FONT FACE=3D"Lucida Sans"> V5=3D" -c "</FONT>
<BR><FONT FACE=3D"Lucida Sans">else</FONT>
<BR><FONT FACE=3D"Lucida Sans"> V5=3D""</FONT>
<BR><FONT FACE=3D"Lucida Sans">fi</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">su dbadmin ${V5} "/usr/bin/rsh $HOST =
$COMMAND"</FONT>
<BR><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>>>>&g=
t;>>>>>>>>>>>>>></FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">there is indeed no man page in 4.0d, but =
in my 4.0d system (on a 4100, too,</FONT>
<BR><FONT FACE=3D"Lucida Sans">with Patch Kit 4) the following command =
works without problems:</FONT>
<BR><FONT FACE=3D"Lucida Sans">su - steffi -c do_something</FONT>
<BR><FONT FACE=3D"Lucida Sans">where do_something is a script lying in =
my home directory.</FONT>
<BR><FONT FACE=3D"Lucida Sans">Attention: the first "-" has =
two blanks around it, the "-c" is written - as</FONT>
<BR><FONT FACE=3D"Lucida Sans">usually - without a blank =
between.</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">And voila: the man page from 3.2g</FONT>
</P>
<P><FONT FACE=3D"Lucida =
Sans">su(1) &=
nbsp; &=
nbsp; &=
nbsp; =
su(1)</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">NAME</FONT>
<BR><FONT FACE=3D"Lucida Sans"> su - Substitutes user ID =
temporarily</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">SYNOPSIS</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans"> su [-f] | [-c command] =
| [-] [user]</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">FLAGS</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans"> -c command</FONT>
<BR><FONT FACE=3D"Lucida Sans"> Executes =
the specified command in the user's shell.</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans"> -f Prevents the user's =
shell initialization file from being executed =
by</FONT>
<BR><FONT FACE=3D"Lucida Sans"> passing =
the -f option to the user's shell, thus making su start up =
fas-</FONT>
<BR><FONT FACE=3D"Lucida Sans"> =
ter.</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans"> - =
Simulates a full login =
by executing the commands in either the =
.cshrc</FONT>
<BR><FONT FACE=3D"Lucida Sans"> and =
.login files for csh or the .profile file =
for sh and ksh and by</FONT>
<BR><FONT FACE=3D"Lucida Sans"> setting =
the current working directory to the user's home directory.</FONT>
</P>
<P><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>>>>&g=
t;>>>>></FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">I tried several variations on my system =
(4.0D with patch kit 7 installed) and su - username -c script worked on =
all except one. That was when the script did not have execute =
permission. Are you sure the execute bits are set? Does the =
script have a "#!/path/to/interpreter" comment at the =
top?</FONT></P>
<P><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans">BTW, to answer one question, =
su passes the -c to the shell invoked by the su - username</FONT>
</P>
<P><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>>>>&g=
t;>>>>>>></FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">The -c option does work on v4.0d.</FONT>
<BR><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans">In my KSH script that starts and stop my =
Oracle Apps and DBMS I'm using the command :</FONT>
<BR><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans">/usr/bin/su - ${DBUSER} -c =
"ORACLE_SID=3D$lSID ; export ORACLE_SID ; svrmgrl" =
>>$LOGFILE 2>&1</FONT>
<BR><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans">With the env variables assigned =
appropriately it works flawlessly.</FONT>
<BR><FONT FACE=3D"Lucida Sans">The script may be the name of a script =
to execute or any other valid command line. Keep in mind that the =
environment that the script will execute under is that of the user that =
you are su'ing to, so that user's path, etc. must be set =
correctly.</FONT></P>
<P><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>></FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">Have you tried sudo? It allows a system =
administrator to give some users the right to run some commands as root =
or as another user. I believe it allow root to run commands as another =
user, also. Look at the sudo web page at: </FONT></P>
<P><FONT FACE=3D"Lucida Sans"><A =
HREF=3D"http://www.courtesan.com/sudo/" =
TARGET=3D"_blank">http://www.courtesan.com/sudo/</A> </FONT>
</P>
<P><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>>>>&g=
t;>>.</FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">I suggest the su - <username> -c =
"script" syntax is meant for crontab; ie. such that cron runs =
the script instead of a user doing it interactively.</FONT></P>
<P><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida =
Sans">>>>>>>>>>>>>>>>>&g=
t;></FONT>
</P>
<P><FONT FACE=3D"Lucida Sans">Try using rsh instead. </FONT>
<BR><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans"># rsh <node> -l <user> =
<command></FONT>
<BR><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans">You will need a ".rhosts" file =
on the remote node though. More information from "man rsh". =
Hope this helps.</FONT>
<BR><FONT FACE=3D"Lucida Sans"> </FONT>
<BR><FONT FACE=3D"Lucida Sans">>>>>>>>>>>&=
gt;>>>>>>>>></FONT>
</P>
<P><B><FONT COLOR=3D"#008000" SIZE=3D5 FACE=3D"Lucida =
Calligraphy">Jackie R. Miller</FONT><FONT COLOR=3D"#008000" SIZE=3D5 =
FACE=3D"Gigi"></FONT> =
=
</B>=20
<BR><FONT COLOR=3D"#008000" FACE=3D"Garamond">Director, Information =
Systems</FONT>
<BR><FONT COLOR=3D"#008000" FACE=3D"Garamond">Whitworth College</FONT>
<BR><FONT COLOR=3D"#008000" FACE=3D"Garamond">509 777-4486</FONT>
<BR> =
=
=
=
=
=
=20
</P>
<BR>
</BODY>
</HTML>
------_=_NextPart_001_01C09DEF.00908630--
reply other threads:[~2001-02-23 23:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox