home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / admin / 4375 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  1.7 KB

  1. Xref: sparky comp.unix.admin:4375 comp.unix.shell:3199 comp.unix.questions:9566
  2. Newsgroups: comp.unix.admin,comp.unix.shell,comp.unix.questions
  3. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbfsb!cbnewsg.cb.att.com!cooper
  4. From: cooper@cbnewsg.cb.att.com (Ralph 'Hairy' Moonen)
  5. Subject: Re: Logging in as root within a shell script
  6. Message-ID: <1992Jul30.075910.5793@cbfsb.cb.att.com>
  7. Followup-To: comp.unix.questions
  8. Sender: news@cbfsb.cb.att.com
  9. Organization: AT&T
  10. References: <trung.712443864@sundance>
  11. Date: Thu, 30 Jul 1992 07:59:10 GMT
  12. Lines: 28
  13.  
  14. In article <trung.712443864@sundance>, trung@sundance.SJSU.EDU (Trung Tran) writes:
  15. > I would like to run a shell script which will ask me for the root's password
  16. > before allowing me to do some other administrative tasks.  Once a correct
  17. > password is entered, the script will go on executing the next command
  18. > (instead of starting a root shell).  When all tasks are done, it will
  19. > automatically log out of root shell and continue with the rest of the
  20. > script.  Can someone please tell me if this is possible to achieve.  If so,
  21. > how can it be done?  Or is it too risky?
  22.  
  23. It's allways risky, but OK, here goes:
  24.  
  25. # first part of script here, say start up things, etc....
  26. # next you want to do things in root
  27. su root <<EOF!
  28. # place commands to be executed under root here
  29. EOF!
  30. # place more normal commands here...
  31.  
  32. This will prompt for the root password, and only continue after the 
  33. password has been entered. If an incorrect password is given, the script
  34. just continues execution of the commands that occur after the EOF! line.
  35.  
  36. --Ralph Moonen
  37. -- 
  38. begin 644 ralph.pub
  39. MF58  ]M2*@QR86QP:%]M;V]N96[^ 6- RJ-V"2/)B4[K']_ZR@4#IVQE=TT6
  40. LHD.M[5JN9O_E1]Z9HXM/%A$WW.E[OA8>ES0S+;I@Q::BY.J8/Z]22#4% !$6
  41. end
  42.