home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part06 / purge_mvfil.sh < prev    next >
Text File  |  1992-09-08  |  10KB  |  288 lines

  1.  
  2. Here are the latest copies of the XBBS Sysop's utilities purge & mvfile.sh.
  3. You should find that they will run without modification with the exception of
  4. purge which will require you to correct the path to allign.
  5.  
  6.  
  7. ===================  B E G I N N I N G    O F   P U R G E   ====================
  8. :
  9. # trap " put clean-up code here" 1 2 3 15
  10. #purge
  11. #    This script will assist the XBBS system operator in maintaining
  12. #    the users lists.
  13. #
  14. #    Copyright Dighera Data Services  July 20, 1987
  15. #
  16.  
  17. # This command should assure that the user.bbs file has been 'alligned',
  18. # then prompt the sysop for a date, range of dates, name, or other search
  19. # criteria, present matching users names individually and ask if they should be
  20. # purged, if yes, then purge their records from: user.bbs, userpriv.bbs, and 
  21. # messages.log in each of the message directories.  The deletion is most easily
  22. # accomplished with grep -vf , sed, awk, or ed.
  23.  
  24. NAME="`basename $0`"                # The Name of this Script
  25. HOMEDIR="`grep '^bbs:' /etc/passwd | awk -F\":\" '{print $6}'`"    # XBBS home dir
  26. BINDIR="`head -21 $HOMEDIR/.config.bbs | tail -1`"        # XBBS binaries
  27. USERFIL="`head -7 $HOMEDIR/.config.bbs | tail -1`"        # Users dBASE
  28. PRIVFIL="`head -13 $HOMEDIR/.config.bbs | tail -1`"        # Privlege File
  29. MSGMENU="`head -23 $HOMEDIR/.config.bbs | tail -1`"        # Message Areas
  30. MSGLOG="messages.log"                        # Message Log 
  31. export NAME HOMEDIR BINDIR USERFIL PRIVFIL MSGMENU MSGLOG
  32. echo "\014\n\n\n\tX B B S    U S E R    P U R G E    M E N U \n\n"
  33. #
  34. #  Save a copy of all files that will be modified
  35. #
  36. if [ -f ${USERFIL}.o ]
  37. then
  38.     echo "${USERFIL}.o exists.  Ok to overwrite it? \c"
  39.     read ANS
  40.     case $ANS in
  41.         [yY]*) :;;
  42.         *) echo "${NAME}: Aborting ..."; exit 1;;
  43.     esac
  44. else
  45.     cp $USERFIL ${USERFIL}.o
  46. fi
  47. if [ -f ${PRIVFIL}.o ]
  48. then
  49.     echo "${PRIVFIL}.o exists.  Ok to overwrite it? \c"
  50.     read ANS
  51.     case $ANS in
  52.         [yY]*) :;;
  53.         *) echo "${NAME}: Aborting ..."; exit 1;;
  54.     esac
  55. else
  56.     cp $PRIVFIL ${PRIVFIL}.o
  57. fi
  58. #
  59. # Allign the users file
  60. #
  61. FLAG=0; export FLAG
  62. echo "\nAllinging $USERFIL file ...\nPlease stand by ...\c"
  63. echo "$USERFIL" >/tmp/$NAME.tmp
  64. # You will have put the path to your allign program here
  65. #$BINDIR/allign/allign </tmp/$NAME.tmp 2>&1 > /dev/null || (echo "${NAME}: cannot allign, aborting ..."; FLAG=1)
  66. $USERFIL/allign </tmp/$NAME.tmp 2>&1 > /dev/null || (echo "${NAME}: cannot allign, aborting ..."; FLAG=1)
  67. rm -f /tmp/$NAME.tmp
  68. if [ $FLAG -eq 1 ];then exit 1;fi
  69. #
  70. # Display Menu
  71. #
  72. echo "\014"
  73. cat << EOT
  74.  
  75.  
  76.         X B B S   U S E R    P U R G E    M E N U
  77.  
  78.  
  79.     N.  Purge Users by NAME
  80.     D.  Purge Users by DATE
  81.     C.  Purge Users that have ONLY CALLED ONCE
  82.     P.  Purge Users by PRIVLEGE LEVEL
  83.     B.  Purge Users by PRIVLEGE LEVEL & ONLY CALLED ONCE
  84.  
  85.     Q.  Quit to Unix
  86. ?
  87. EOT
  88. read CHOICE
  89. case $CHOICE in 
  90.     [nN]*) echo "${NAME}: This command is not implemented yet";;
  91.     [dD]*) echo "${NAME}: This command is not implemented yet";;
  92. # Find all user records with first-session-date = last-session-date, and
  93. # present them for deletion from users data base.
  94. #
  95.     [cC]*) echo "\nSearching $USERFIL for One-time-callers...\c";
  96.         rm -f /tmp/$NAME.found /tmp/$NAME.prv.rm /tmp/$NAME.priv > /dev/null 2>&1 ;
  97.         awk -F"~" '$5 == $7 {print}' $USERFIL >> /tmp/$NAME.found && echo "Search Completed!";
  98. # This trap needs to address processing the other files created by split
  99.         if [ `wc -l /tmp/$NAME.found | awk '{print $1}'` -gt 900 ]
  100.         then
  101.             echo "File contains more than 900 lines; being split.."
  102.             split /tmp/$NAME.found /tmp/$NAME.found.
  103.             cp /tmp/$NAME.found.aa /tmp/$NAME.found
  104.         fi;
  105.         echo "Please stand by ... \c";
  106.         for I in `awk -F"~" '{print $1"~"$2"~"}' /tmp/$NAME.found`
  107.         do
  108.             J="`echo \"$I\" | awk -F\"~\" '{print $1, $2, }'`"
  109.             export J
  110.             echo "\nPriv Record: \c"
  111.             fgrep "$J" $PRIVFIL | tee /tmp/$NAME.priv
  112.             if [ -s /tmp/$NAME/priv ]; then echo "\007";fi
  113.             echo "User Record: \c"
  114.             fgrep "$I" /tmp/$NAME.found
  115.             echo "\n\tRemove (y,N,p,q)? \c"; read REMOVE
  116.             case $REMOVE in
  117.                 [yY]*) echo "$I" >> /tmp/$NAME.rm;
  118.                       cat /tmp/$NAME.priv >> /tmp/$NAME.prv.rm;;
  119.                 [pP]*) break;;
  120.                 [bB]*) echo "Not yet emplemented";;
  121.                 [qQ]*) exit 1;; # Add exit & clean up code here
  122.                 *) continue;;
  123.             esac
  124.             echo
  125.         done;
  126.         rm -f /tmp/$NAME.found /tmp/$NAME.priv;
  127.         #
  128.         # Create Purged  USERFIL
  129.         #
  130.     # This trap needs to address processing the other files created by split
  131.         if [ `wc -l /tmp/$NAME.rm | awk '{print $1}'` -gt 200 ]
  132.         then
  133.             echo "File contains more than 200 lines; being split.."
  134.             split /tmp/$NAME.rm /tmp/$NAME.rm.
  135.             cp /tmp/$NAME.rm.aa /tmp/$NAME.rm
  136.         fi
  137.         fgrep -vf /tmp/$NAME.rm $USERFIL >${USERFIL}NEW;
  138.         cp ${USERFIL}NEW $USERFIL && rm ${USERFIL}NEW;
  139.         #
  140.         # Create Purged PRIVFIL
  141.         #
  142.     # This trap needs to address processing the other files created by split
  143.         if [ `wc -l /tmp/$NAME.prv.rm | awk '{print $1}'` -gt 200 ]
  144.         then
  145.             echo "File contains more than 200 lines; being split.."
  146.             split /tmp/$NAME.prv.rm /tmp/$NAME.prv.rm.
  147.             cp /tmp/$NAME.prv.rm.aa /tmp/$NAME.prv.rm
  148.         fi
  149.         fgrep -vf /tmp/$NAME.prv.rm $PRIVFIL >${PRIVFIL}NEW;
  150.         cp ${PRIVFIL}NEW $PRIVFIL && rm ${PRIVFIL}NEW;
  151.         #
  152.         # Create Purged MSGFIL
  153.         #
  154.         for J in `awk 'NR > 1 {print $1}' $MSGMENU`
  155.         do
  156.             cd $BINDIR/$J
  157.             fgrep -vf /tmp/$NAME.prv.rm $MSGLOG >${MSGLOG}NEW
  158.             cp $MSGLOG o$MSGLOG && (cp ${MSGLOG}NEW $MSGLOG; rm ${MSGLOG}NEW)
  159.         done;
  160.         # add clean-up code here
  161.         rm /tmp/$NAME.rm /tmp/$NAME.prv.rm;;
  162.     [pP]*) echo "${NAME}: This command is not implemented yet";;
  163.     [qQ]*) exit 0;;
  164.     *) ;;
  165. esac
  166. exec $0
  167. # trap 1 2 3 15
  168. ============================  E N D    O F    P U R G E  ====================
  169.  
  170. ===================  B E G I N N I N G    O F    M V F I L E . S H  ======
  171. :
  172. #mvfile.sh     Version 1.0 Beta
  173. #    This Bourn shell script will assist the Sysop in moving
  174. #    files that have been uploaded by XBBS users to their 
  175. #    respective directories.
  176. #
  177. #    Copyright Dighera Data Services September 5, 1987
  178. #
  179.  
  180. NAME=`basename $0`    # The name of this program
  181. SRCDIR=""        # Directory name containing files to be moved
  182. DESTDIR=""        # Directory name that will receive file
  183. JUNKDIR=/usr/tmp    # Destination for junked files
  184. FLINE=""        # Line from files.bbs that describes file
  185. HOMEDIR="`grep '^bbs:' /etc/passwd | awk -F\":\" '{print $6}'`"    # XBBS home dir
  186. ORGDIR=`cat $HOMEDIR/.config.bbs | awk 'NR == 21 {print}' -`    # XBBS Origin 
  187. AREAS_BBS=`cat $HOMEDIR/.config.bbs | awk 'NR == 22 {print}' -`    # File w/ areas
  188. AREAS=`cat $AREAS_BBS | awk 'NR > 1 { print $1 }'`    # All file areas
  189. # AREA_NO=`expr \`wc -l $AREAS_BBS | awk '{print $1}'\` - 1`
  190. set $AREAS
  191. AREA_NO=$#
  192. MENU="cat /usr/tmp/$NAME.mnu"
  193. export NAME HOMEDIR ORGDIR AREAS_BBS AREAS AREA_NO SRCDIR FLINE DESTDIR MENU SORT DAYS
  194. trap "echo \"\007$0: Aborted\"; eval rm /usr/tmp/$NAME.mnu; exit 2" 1 2
  195.  
  196. #    Make Menu File
  197. echo "\014\n\t    X B B S    F I L E    D I S P E R S A L    M E N U\n\n" > /usr/tmp/$NAME.mnu
  198. echo "\t\tEnter the Number of Your Choice --\n" >> /usr/tmp/$NAME.mnu
  199. for I
  200. do
  201.     echo "$I" >> /usr/tmp/$NAME.mu
  202. done
  203. cat /usr/tmp/$NAME.mu | pr -3t -n -o8 >>/usr/tmp/$NAME.mnu
  204. echo >> /usr/tmp/$NAME.mnu
  205. rm /usr/tmp/$NAME.mu
  206.  
  207. #
  208. #    Main Program Begins
  209. #
  210. cd $ORGDIR    # No doubt this is the cause of the exec $0's failing
  211. $MENU
  212. echo "Enter the Number of the Source Directory\ncontaining the files you wish to move: \c"
  213. read SRCDIR
  214. case $SRCDIR in
  215.   1[123] | [0123456789]) SRCDIR=`echo $AREAS | awk '{print $'$SRCDIR'}'`;;
  216.   *) echo "Invalid Input\007"; sleep 3; exec $0;;     # Bug here $0
  217. esac
  218. # This section needs work !!!!!!!!!!!!!!!!!!!!!
  219. while true
  220. do
  221.    head -6 /usr/tmp/$NAME.mnu
  222.    cat << EOT
  223.  
  224.     1.  Sort $SRCDIR ALPHABETICALLY (default)
  225.     2.  Sort $SRCDIR REVERSED ALPHABETICAL
  226.     3.  Sort $SRCDIR BEGINNING with Specific Characters
  227.     4.  Sort $SRCDIR OLDest first
  228.     5.  Sort $SRCDIR NEWest first
  229.     6.  Show $SRCDIR files LESS THAN A NUMBER OF DAYS OLD
  230.     7.  Show $SRCDIR files MORE THAN A NUMBER OF DAYS OLD
  231. ?
  232. EOT
  233.    read CHOICE
  234.    case $CHOICE in
  235.     1) CMD="ls $SRCDIR"; break;;
  236.     2) CMD="ls -r $SRCDIR"; break;;
  237. # The choice below only returns ONE filename; bug
  238.     3) echo "\n\tEnter characters for begining of file name \c"; read SORT;
  239.         CMD='basename `ls $SRCDIR/$SORT*`'; break;;
  240.     4) CMD="ls -tr $SRCDIR"; break;;
  241.     5) CMD="ls -t $SRCDIR"; break;;
  242. # The two choices below don't fine any filenames; bug
  243.     6) echo "Enter the NUMBER of DAYS";read DAYS; CMD="find $SRCDIR -ctime -$DAYS -print"; break;;
  244.     7) echo "Enter the NUMBER of DAYS";read DAYS; CMD="find $SRCDIR -ctime +$DAYS -print"; break;;
  245.     *) CMD="ls $SRCDIR"; break;;
  246.    esac
  247. done
  248. #
  249. #    Main Loop
  250. #
  251. echo "$CMD"
  252. for J in `eval "$CMD"`
  253. do
  254.    if [ ! -f $SRCDIR/$J ] ;then continue; fi    # Don't process directories
  255.    $MENU
  256.    echo "\tQ.\tQuit to Unix\n\tN.\tNext File (don't move this one)\n\tJ.\tJunk this File (in $JUNKDIR)\n"
  257.    FLINE="`grep ^$J $SRCDIR/files.bbs || (echo \"\007$0: File $J probabily not referenced in $SRCDIR/files.bbs.\"; sleep 3; continue)`"
  258.    test `echo "$FLINE" | wc -l` -gt 1 && (echo "\007$0: File $J probabily referenced more than once in $SRCDIR/files.bbs"; sleep 3 ; continue)
  259.    echo "Move?: $FLINE\n"
  260.    ls -la $SRCDIR/$J
  261.    echo "\nEnter the Number of the Distination Directory: \c"
  262.    read CHOICE
  263.    case $CHOICE in
  264.      [qQ]*) exit;;
  265.      [nN]*) continue;;
  266.     [jJ]*) mv $SRCDIR/$J $JUNKDIR;
  267.          grep -v "$FLINE" $SRCDIR/files.bbs > /usr/tmp/$NAME.$$ || (echo " $0: grep error" ; sleep 3; continue);
  268.         if [ -s /usr/tmp/$NAME.$$ ] ;then cp /usr/tmp/$NAME.$$ $SRCDIR/files.bbs
  269.         else echo "\007$0: 0 length file error"; exit 1 ; fi
  270.         rm /usr/tmp/$NAME.$$;
  271.         echo $FLINE >> $JUNKDIR/files.bbs;;
  272.      [0-9] | 1[0-2]) DESTDIR=`echo $AREAS | awk '{print $'$CHOICE'}'`;
  273.          grep -v "$FLINE" $SRCDIR/files.bbs > /usr/tmp/$NAME.$$ || (echo " $0: grep error" ; sleep 3; continue);
  274.         mv $SRCDIR/$J $DESTDIR;
  275.         if [ -s /usr/tmp/$NAME.$$ ] ;then cp /usr/tmp/$NAME.$$ $SRCDIR/files.bbs
  276.         else echo "\007$0: 0 length file error"; exit 1 ; fi
  277.         rm /usr/tmp/$NAME.$$;
  278.          echo $FLINE >> $DESTDIR/files.bbs;;
  279. # Add edit option here for $DESTDIR/files.bbs
  280.      *) echo "\007Your entery '$CHOICE' is not amoung the valid choices. Continuing ..."; sleep 2 ;;
  281.    esac
  282. done
  283. rm /usr/tmp/$NAME.mnu
  284. trap 1 2 3 9 15
  285. ===========================  E N D    O F    M V F I L E . S H   =============
  286.  
  287.