switching user in shell

switching user in shell

am 25.01.2008 17:09:54 von george.e.sullivan

Hi All,

I want to run a cronjob that uses a shell script.

The script simply does:

#!/bin/csh -f
su - sully
touch /apps/testfile
touch /data/testfile

Then chmod it so it executes.

The su to sully spawns a child I imagine and the touch commands then
try
and run as root, I think. Or the first touch runs a sully and the
second does not.
My root mail is saying permission denied on /data/testfile for
example, though
at the command line, as sully, I can do the touches.

Anyway....

How do I switch to sully, run the two touch commands, then exit or do
I do the
su in the cron.

Thanks

Re: switching user in shell

am 25.01.2008 19:33:22 von OldSchool

On Jan 25, 11:09=A0am, George wrote:
> Hi All,
>
> I want to run a cronjob that uses a shell script.
>
> The script simply does:
>
> #!/bin/csh -f
> su - sully
> touch /apps/testfile
> touch /data/testfile
>
> Then chmod it so it executes.
>
> The su to sully spawns a child I imagine and the touch commands then
> try
> and run as root, =A0I think. Or the first touch runs a sully and the
> second does not.
> My root mail is saying permission denied on /data/testfile for
> example, though
> at the command line, as sully, I can do the touches.
>
> Anyway....
>
> How do I switch to sully, run the two touch commands, then exit or do
> I do the
> su in the cron.
>
> Thanks

as soon as you do the "su - sully" as shown, you effectively leave
your script, so the touch is being hit. assuming you're running as
root a couple of possibilities come to mind:

su - sully -c /path_to_yourscript

if the entire thing can be run as "sully"

alternatively, change your script above such that it touches the
files, then sets required permissions, then does a chown so that sully
owns it if necessary. Based on what you've said above, I think I'd
go this route....and change to something other than csh