home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / sun / admin / 9607 < prev    next >
Encoding:
Text File  |  1992-12-21  |  4.0 KB  |  121 lines

  1. Newsgroups: comp.sys.sun.admin
  2. Path: sparky!uunet!caen!spool.mu.edu!solaria.mil.wi.us!jgreco
  3. From: jgreco@solaria.mil.wi.us (Joe Greco)
  4. Subject: Re: Can single user mode be entered and exited from a script?
  5. Message-ID: <BzHz3B.9Aq@solaria.mil.wi.us>
  6. Keywords: single-user backup dump
  7. Organization: Solaria Public Access UNIX - Milwaukee, WI
  8. References: <BzH5JL.Mz5@netnews.jhuapl.edu>
  9. Date: Sat, 19 Dec 1992 08:18:46 GMT
  10. Lines: 109
  11.  
  12. In comp.sys.sun.admin article <BzH5JL.Mz5@netnews.jhuapl.edu>, humesdg1@netnews.jhuapl.edu (Dave Humes) wrote:
  13. :
  14. :Is there any way to bring a SunOS system to single user mode from a shell
  15. :script, and have the script resume multi-user mode?  I have operators do our 
  16. :backups in the evening by logging into an account that starts a script to
  17. :do the backup.  It works fine, but files can be open if people are still on.
  18. :I'd rather not have to give them the root password or root priviliges just to
  19. :get the system into single user mode.
  20.  
  21. Ah, yes.  I've used this horrible trick for about three years, originally on
  22. IBM RT 6152 workstations where I had some problem where I had to reboot from
  23. remote.  This was something I devised when I was still a little wet behind 
  24. the ears dealing with singleuser mode, but it's simple, relatively secure 
  25. if you want it to be, and easily adapted to other uses.
  26.  
  27. I add the following to root's /.profile:
  28. ------------------------------------------------------------------------------
  29. if [ -f /backup.script ]; then
  30.     echo ""
  31.     echo Executing /backup.script
  32.     date
  33.     rm -f /backup.exe
  34.     mv /backup.script /backup.exe
  35.     sh -c /backup.exe
  36.     echo Done
  37.     date
  38.     rm -f /backup.exe
  39.     exit 0
  40. fi
  41. if [ -f /backup.exe ]; then
  42.     echo ""
  43.     echo WARNING: A backup script has failed, see /backup.exe!
  44.     echo ""
  45. fi
  46. ------------------------------------------------------------------------------
  47.  
  48. I run the following from cron in the wee hours to do my incrementals.
  49. ------------------------------------------------------------------------------
  50. #! /bin/sh -
  51.  
  52. PATH=/usr/ucb:/bin:/usr/bin:/etc:/usr/etc:/usr/local/adm:/usr/lib; export PATH
  53.  
  54. /bin/sh - << END_OF_CRON 2>&1 | cronmail sroot "Daily Backup Cron Report"
  55.  
  56. device1=/dev/rmt8
  57. script=/backup.script
  58.  
  59. ####################
  60. # MUST check for a "sense key= not ready"!!!
  61. ###################
  62. if (2>&1 mt -f ${device1} status > /dev/null); then
  63.     sleep 1
  64. else
  65.     logger -p daemon.err -t backup.daily "Tape not loaded."
  66.     echo "Tape not loaded."
  67.     exit 1
  68. fi
  69.  
  70. cat - << EOF > ${script}
  71. #! /bin/sh -
  72.  
  73. PATH=/usr/ucb:/bin:/usr/bin:/etc:/usr/etc:/usr/lib; export PATH
  74.  
  75. # do the backups here
  76. mt -f ${device1} fsf 2
  77. # do the backups here
  78.  
  79. mt -f ${device1} rewind
  80. mt -f ${device1} offline
  81.  
  82. exit 0
  83. EOF
  84.  
  85. chmod 755 ${script}
  86.  
  87. shutdown +30 "System going down for daily backups"
  88.  
  89. 2>&1 mt -f ${device1} rewind > /dev/null
  90.  
  91. sleep 1860
  92.  
  93. echo "Major malfunction, system failed to shut down for backups!"
  94.  
  95. END_OF_CRON
  96.  
  97. exit 0
  98. ------------------------------------------------------------------------------
  99.  
  100. I use a little script called "cronmail" to add subjects to my cron reports
  101. and mail them to selective users, and there's a wrapper to set the env the
  102. way I need it.  So the real meat is between the /bin/sh - << END_OF_CRON and
  103. the END_OF_CRON.  When this runs, it creates a file in the root directory,
  104. containing a shell script of things to be done in singleuser mode.  It then
  105. does a regular shutdown, which should land the system in singleuser mode in
  106. 30 minutes.  It takes advantage of this time to rewind the tape...
  107.  
  108. At 30 minutes, the system shuts down, init starts a sh on console, reading
  109. the booby-trapped .profile which instead meanders off to do my script.  NOTE
  110. that the file-"shuffling" is *VERY* important, if the file is not renamed it
  111. will be somewhat difficult to get into singleuser mode again.
  112.  
  113. The system restarts when the script terminates.  Bingo.  Automated 4am
  114. singleuser mode backups while-u-sleep.
  115.  
  116. ... Joe
  117.  
  118. -------------------------------------------------------------------------------
  119. Joe Greco - System Administrator               jgreco@solaria.mil.wi.us
  120. Solaria Public Access UNIX - Milwaukee, WI               414/321-9287
  121.