Re: [OT] change user when executing some script



On Wed, Jun 13, 2007 at 05:12:34PM +0200, Galevsky wrote:

Let's have 3 users: user1, user2 and user3
let's have a user1 script: /home/user1/script.sh

Script is:

#!/bin/bash
if [ -f '/home/user1/testfile' ]
then rm /home/user1/testfile
else touch /home/user1/testfile
fi


Both user2 and user3 can execute it. What I want is user3 be able to
delete the file that was created before by user2 during a previous
run. But I fail to find a solution. Even if user1 set the
setuid/setgid flag on the script file, the file /home/user1/testfile
belongs to user2 and user3 won't be able to delete the file.

How can I make the /home/user1/testfile belong to user1, the owner of
the script instead of the user that launches it ?


On DEBIAN, to remove a file, you need write permissions on the directory
in which it resides. I suppose user1 could give group write to the
directory. You would then create a group and put user[1-3] in that
group.

Doug.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: 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. ...
    (Fedora)
  • "Senden als.." ohne "Im Auftrag von xyz"
    ... Habe hier User1, User2 und User3. ... User1 kann im Auftrag von User2 Mails verschicken. ... ohne "User1 im Auftrag von User2" ...
    (microsoft.public.de.german.exchange2000.general)
  • adding users from a file

    (comp.unix.shell)
  • "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)
  • mehrsprachiges System
    ... User1 -> deutsch ... User2 -> englisch ... User3 -> spanisch ... Danke & schöne Grüße ...
    (microsoft.public.de.german.sharepointportalserver)