home *** CD-ROM | disk | FTP | other *** search
/ ftp.jcu.edu.au / 2014.06.ftp.jcu.edu.au.tar / ftp.jcu.edu.au / v6.3.2b / SWBD63 / fabos-6.3.2b-10.ppc.rpm / fabos-6.3.2b.10.cpio.gz / fabos-6.3.2b.10.cpio / fabos / libexec / coreffdc.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2010-11-10  |  3KB  |  132 lines

  1. #!/bin/sh
  2. CORE_ROOT=/
  3. CORE_FILES_DIR=core_files
  4. MNT_DIR=mnt
  5. CORE_TAR=*.tar
  6. PATH=/bin:/usr/bin:
  7. export ROLE_ID="root"
  8.  
  9. # Function to get a list of core files
  10. getCoreFileList() {
  11.     core_files_list=`/usr/bin/find ${CORE_ROOT}${CORE_FILES_DIR} ${CORE_ROOT}${MNT_DIR}/${CORE_FILES_DIR} \( -name "*ffdc*" -o -name "*core*" \) -type f -print 2> /dev/null`
  12.     
  13.     if [ -z "${core_files_list}" ]
  14.     then
  15.         printf "No core or FFDC data files found!\n"
  16.         exit
  17.     fi
  18.     tmpList=""
  19.     for coreFile in ${core_files_list}
  20.     do
  21.         tmpList="${tmpList}  `/usr/bin/dirname ${coreFile}`"
  22.     done
  23.     core_files_list=`/bin/ls -d $tmpList | /bin/sort | /usr/bin/uniq`
  24.     idx=0
  25.     for coreFile in ${core_files_list}
  26.     do
  27.         coreFileArry[${idx}]="${coreFile}"
  28.         coreSelArry[${idx}]=" "
  29.         idx=`/fabos/bin/expr ${idx} + 1`
  30.     done
  31.     coreFilesCount=$idx
  32. }
  33.  
  34. # function to just list files on the terminal
  35. tarAllFiles() {
  36.     core_files_list=`/usr/bin/find ${CORE_ROOT}${CORE_FILES_DIR} ${CORE_ROOT}${MNT_DIR}/${CORE_FILES_DIR} \( -name "*ffdc*" -o -name "*core*" \) -type f -print 2> /dev/null`
  37.     
  38.     if [ -z "${core_files_list}" ]
  39.     then
  40.         printf "No core or FFDC data files found!\n"
  41.         exit 0
  42.     fi
  43.     chmod 666 ${core_files_list}
  44.     tmpList=""
  45.     for coreFile in ${core_files_list}
  46.     do
  47.         tmpList="${tmpList}  `/usr/bin/dirname ${coreFile}`"
  48.     done
  49.     core_files_list=`/bin/ls -d $tmpList | /bin/sort | /usr/bin/uniq`
  50.     idx=0
  51.  
  52.     if [  $argLog -eq 1 ]
  53.     then
  54.         printf "tar file:${core_files_list}\n"
  55.     fi
  56.  
  57.     tar -czPf ${cmdFileName} ${core_files_list}  2> /dev/null
  58. }
  59.  
  60.  
  61. # Function to remove ALL core files
  62. rmCoreFilesListAll() {
  63.     idx=0
  64.     while [ $idx -lt $coreFilesCount ]
  65.     do
  66.         printf " removing files under: %s\n" ${coreFileArry[$idx]}
  67.         /bin/rm -f ${coreFileArry[$idx]}/*
  68.         # for fdet and ptlog in /core_files/
  69.         name=${coreFileArry[$idx]:12:5}
  70.         # for fdet and ptlog in /mnt/core_files/
  71.         name1=${coreFileArry[$idx]:16:5}
  72.         if [ "$name" = "fdet." -o "$name" = "ptlog" ] ||
  73.            [ "$name1" = "fdet." -o "$name1" = "ptlog" ]
  74.         then
  75.             /bin/rmdir ${coreFileArry[$idx]}
  76.         fi
  77.         idx=`/fabos/bin/expr ${idx} + 1`
  78.     done
  79.     #printf "reset fddc control count"
  80.     rm -f /core_files/*.tar
  81.     /fabos/sbin/supportuffdc -p
  82.  
  83. }
  84.  
  85. # main starts here
  86.     argRemoveAll=0            # Remove ALL core files        (-R)
  87.     argFtpAnon=""        # FTP   user is anonimous   (-a)
  88.     argRemoveTar=0            # FTP   user is anonimous   (-t)
  89.     argLog=0                # FTP   user is anonimous   (-l)
  90.  
  91. # get the command options, if any
  92.     while getopts Rla:t: c
  93.     do
  94.         case $c in
  95.         R) argRemoveAll=1
  96.            ;;
  97.         a) argFtpAnon=$OPTARG
  98.            ;;
  99.         t) argRemoveTar= $OPTARG
  100.            ;;
  101.         l) argLog=1
  102.            ;;
  103.         *)
  104.            exit -1
  105.            ;;
  106.         esac
  107.     done
  108.  
  109.     # Remove all Files
  110.     if [  $argRemoveAll -eq 1 ]
  111.     then
  112.         getCoreFileList
  113.         rmCoreFilesListAll
  114.         
  115.         exit 0
  116.     fi
  117.     # create tar file 
  118.     if [ -n "${argFtpAnon}" ]
  119.     then
  120.         cmdFileName="${argFtpAnon}"
  121.          tarAllFiles
  122.         exit 0
  123.     fi
  124.  
  125.     # remove created tarfile 
  126.     if [ -n "${argRemoveTar}" ]
  127.     then
  128.         cmdFileName="${argRemoveTar}"
  129.         /bin/rm -f ${CORE_ROOT}${CORE_FILES_DIR}${CORE_ROOT}${cmdFileName}
  130.         exit 0
  131.     fi
  132.