Results 1 to 2 of 2

Thread: shell scripting....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2004
    Location
    youngstown, oh
    Posts
    202

    shell scripting....

    hi there, does anyone here know much about scripting. i'm doing a c-shell now. and i need some help with homework, so if anyone is around and is about shell-scripts let me know, if you can help it would be appercaited....

    me and my partner sat down a did most of the project but i think we get a cppl of errors, and i can't figure them out. illl post my code in like 15mins....

    thanks - justin

    ok ok .....here's the code that me and my partner have.

    Code:
    #! /usr/bin/sh
    
    #---------------------------------------#
    #                                       #
    # Project 1                             #
    #                                       #
    # Lists all files from the              #
    #       current directory that          #
    #       match a specified pattern &     #
    #       are newer, older, or the same   #
    #       as a given date                 #
    #                                       #
    #---------------------------------------#
    
    #---------------------------------------#
    #                                       #
    # Get the search pattern                #
    #                                       #
    #---------------------------------------#
    
    echo Please enter search pattern
    
    read Pattern
    
    #---------------------------------------#
    #                                       #
    # Get the date in the form mm dd yyyy   #
    #                                       #
    #---------------------------------------#
    
    echo Please enter Month
    
    read MonthIn
    
    echo Please enter Day
    
    read DayIn
    
    echo Please enter Year
    
    read YearIn
    
    #---------------------------------------#
    #                                       #
    # Get the flag    1 = newer than        #
    #                 2 = older than        #
    #                 3 = same as           #
    #                                       #
    #---------------------------------------#
    
    echo Please enter a 1 for newer, 2 for older, or 3 for same as
    
    read Flag
    
    #---------------------------------------#
    #                                       #
    # Send the pattern output to a file     #
    #                                       #
    #---------------------------------------#
    
    ls -ld $Pattern > /tmp/tempfile
    
    #---------------------------------------#
    #                                       #
    # Remaining input comes from the file   #
    #                                       #
    #---------------------------------------#
    
    exec < /tmp/tempfile
    
    #---------------------------------------#
    #                                       #
    # Display proper heading                #
    #                                       #
    #---------------------------------------#
    
    if test $Flag -eq 1
          then
            FlagIn='after'
    
    elif test $Flag -eq 2 
          then
              FlagIn='before'
    
    else
             FlagIn='on'
    
    fi
    
    echo
    
    echo The files below were last modified $FlagIn $MonthIn $DayIn $YearIn 
    
    #---------------------------------------#
    #                                       #
    # Loop to process file lines            #
    #                                       #
    #---------------------------------------#
    
    read AccessRight Links UserId GroupId Size Month Day YearOrTime 
    FileName
    
    while [ a = a ]
    do
            #---------------------------------------#
            #                                       #
            # Determine time (1) or year (2)        #
            #                                       #
            #---------------------------------------#
            
            case $YearOrTime in
                 ??:??)
                      IsThereColon=1
                      ;;
    
                 *)
                      IsThereColon=2
                      ;;
    
            esac
       
            #---------------------------------------#
            #                                       #
            # Translate character month to integer  #
            #                                       #
            #---------------------------------------#
    
            if [  $Month = Jan ]
               then
                     Month=1
    
            elif  [ $Month = Feb ]
               then
                  Month=2
    
            elif [ $Month = Mar ]
               then
                  Month=3
    
            elif [ $Month = Apr ]
               then
                  Month=4
    
            elif [ $Month = May ]
               then
                  Month=5
    
            elif [ $Month = Jun ]
               then
                  Month=6
    
            elif [ $Month = Jul ]
               then
                  Month=7
    
            elif [ $Month = Aug ]
                then
                  Month=8
    
            elif [ $Month = Sep ]
               then
                  Month=9
    
            elif [ $Month = Oct ]
               then
                  Month=10
    
            elif [ $Month = Nov ]
               then
                  Month=11
    
            else
    
                  $Month=12
    
            fi
    
    
    
            #---------------------------------------#
            #                                       #
            # Compute correct year                  #
            #                                       #
            #---------------------------------------#
             
            if [ IsThereColon = 2 ]
                 then
                     Year=$YearOrTime
            else
                     CurrentYear=`date '+%Y'`
                     CurrentMonth=`date '+%m'`
          
                     if [ $CurrentMonth -ge 1 -a $CurrentMonth -le 6 ]
                          then 
                              if [ $Month -ge 7 -a $Month -le 12 ]
                                   then
                                       Year=$CurrentYear
                                       Year=`expr $Year - 1`
                              else
                                       Year=$CurrentYear
                              fi
    
                     else
                                       Year=$CurrentYear
                     fi
            fi
    
            #---------------------------------------#
            #                                       #
            # Identify files newer (1) or older (2) # 
            #          for processing               #
            #                                       #
            #---------------------------------------#
    
            if [ $Flag  = 1 ]
                 then
                    
                    if [ $Year -gt $YearIn ]
                       then 
                          echo $FileName
     
                    elif [ $Year = $YearIn ]
                          then
                             if [ $Month -gt $MonthIn ]
                                then 
                                   echo $FileName
                             elif [ $Month = $MonthIn ] 
                                  then
                                     if [ $Day -gt $DayIn ]
                                        then
                                           echo $FileName
                                     fi
                             fi
                    fi                     
    
           elif [ $Flag  = 2 ]
                 then
                    
                    if [ $Year -lt $YearIn ]
                       then 
                          echo $FileName
     
                    elif [ $Year = $YearIn ]
                          then
                             if [ $Month -lt $MonthIn ]
                                then 
                                   echo $FileName
                             elif [ $Month = $MonthIn ] 
                                  then
                                     if [ $Day -lt $DayIn ]
                                        then
                                           echo $FileName
                                     fi
                             fi
                    fi                     
    
            elif [ $Flag = 3 ]
               then
                  if [ $Year = $YearIn -a $Month = $MonthIn -a $Day = $DayIn ]
                     then
                        echo $FileName
                  fi
    
            fi
            read -u4 AccessRight Links UserId GroupId Size Month Day 
    YearOrTime FileName
    
            #---------------------------------------#
            #                                       #
            # Existence test                        #
            #                                       #
            #---------------------------------------#
            
            if [ $AccessRight ]
       
               then
         
                a=a
    
            else
    
              break
    
            fi
    done
    
    #---------------------------------------#
    #                                       #
    # Remove the output file                #
    #                                       #
    #---------------------------------------#
    rm /tmp/tempfile
    ...but we are gettin erros, i will post there erros next. -justin
    Last edited by jlbovo; Mar 28th, 2006 at 09:57 AM.
    --thanks for the help.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2004
    Location
    youngstown, oh
    Posts
    202

    Re: shell scripting....

    Code:
    frodo% project1
    Please enter search pattern
    a
    Please enter Month
    3
    Please enter Day
    3
    Please enter Year
    2003
    Please enter a 1 for newer, 2 for older, or 3 for same as
    1
    a: No such file or directory
    
    The files below were last modified after 3 3 2003
    project1: -u4: is not an identifier
    ....and.....
    Code:
    frodo% project1
    Please enter search pattern
    c*
    Please enter Month
    3
    Please enter Day
    22
    Please enter Year
    2005
    Please enter a 1 for newer, 2 for older, or 3 for same as
    1
    
    The files below were last modified after 3 22 2005
    
    project1: test: argument expected
    --thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width