Switching id bourne shell...

Switching id bourne shell...

Post by Domenic Sion » Sat, 18 Jul 1998 04:00:00



Hi all,
        Need to switch id from root to another defined user in script, return
as root and continue on. Any suggestions would be appreciated.

Thanks in advance,

Domenic

 
 
 

Switching id bourne shell...

Post by David A. Let » Sat, 18 Jul 1998 04:00:00




Quote:>Hi all,
>    Need to switch id from root to another defined user in script, return
>as root and continue on. Any suggestions would be appreciated.

>Thanks in advance,

>Domenic

I'd just localize the part of the script that requires root, and
externalize it.  Then suid it.

 
 
 

Switching id bourne shell...

Post by Donn Ca » Sat, 18 Jul 1998 04:00:00


|       Need to switch id from root to another defined user in script, return
| as root and continue on. Any suggestions would be appreciated.

Here's something I do regularly when unpacking a distribution.
The point is to control file ownerships - tar will try to restore
the original owner UID, and if run by root it will succeed.

   chown bin .
   gzip -d -c whatever-0.9.tar.gz | su bin -c 'tar xf -'

The "tar xf -" command runs as "bin" (which needs a valid shell in
/etc/passwd.)

        Donn Cave, University Computing Services, University of Washington

 
 
 

Switching id bourne shell...

Post by Domenic Sion » Sat, 18 Jul 1998 04:00:00



Quote:

>Hi all,
>        Need to switch id from root to another defined user in script, return
>as root and continue on. Any suggestions would be appreciated.

>Thanks in advance,

>Domenic

Found a solution:

        su - <username> -c "rsh -l <username> <dest-host> <command>"

Thanks anyway.

 
 
 

1. Light Speed Bourne Shell! (was: Bourne shell tricks)

                              WARP SPEED TESTS!

For a light-speed bourne shell script, I just found out a really cool trick:
        if [ "$var" = "condition" ]; then list; fi
becomes:
        case "$var" in "condition") list;; esac

Take this example, two scripts:
        if.sh:
                for x in `jot 1000`; do
                        if [ $x = 1000 ]; then echo "Done"; fi
                        done
        case.sh:
                for x in `jot 1000`; do
                        case $x in 1000) echo "Done";; esac
                        done

("jot" is just some weird util we have here that prints out numbers)
Now take a look at the runtimes (on a DECstation/240 with not much load):
#0 /tmp/JAMtmp> time sh case.sh
                real    0m0.53s
                user    0m0.11s
                sys     0m0.05s
#0 /tmp/JAMtmp> time sh if.sh  
 ^--return code of last cmd in prompt ;-)
                real    0m32.43s
                user    0m1.95s
                sys     0m16.80s
So, case instead of test is:
real:   61 times faster
user:   18 times faster
sys :   31 times faster

...So use case instead of if whenever you can! (just remember the case will
interpret your condition as a pattern!)

--

  n  r    
  a JAMax  "Thou shalt not kill...  Thou shalt not steal...
  h o   w   Thou shalt not covet thy neighbour's...ass nor any
  tan lle   thing that is thy neighbour's."  --Bible

2. PPP and bridging IPX

3. How do I switch to csh in a bourne shell script?

4. Disabling ULTRA-DMA disk option in Solaris 2.7

5. How to switch user id for shell script?

6. Switch from Korn to C shell?

7. Bourne Shell compatible shells (was: Request: which shells)

8. WINE ??

9. Changing from the Bourne shell to C-shell

10. Trying to run nohup from Korn shell but getting Bourne shell errors

11. Bourne Shell vs C-Shell

12. signature of the Bourne shell and the C shell

13. Process history under C-shell and Bourne shell