Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Location
    India
    Posts
    41

    Unanswered: Help needed in Unix Shell Script

    Hi Everbody,

    I wanna write which shuld take the date as input say 02-06-04 and display the output as 02-JUN-2004.


    Thanks and Regards,
    Arun

  2. #2
    Join Date
    Jun 2004
    Posts
    29

    The brute force method

    Code:
    #!/bin/ksh
    
    DAY=`echo $1 | cut -f 1 -d '-'`
    MONTH=`echo $1 | cut -f2 -d '-'`
    YEAR=`echo $1 | cut -f3 -d '-'`
    
    case $MONTH in
    
      01) echo ${DAY}-JAN-$YEAR;;
      02) echo ${DAY}-FEB-$YEAR;;
      03) echo ${DAY}-MAR-$YEAR;;
      04) echo ${DAY}-APR-$YEAR;;
      05) echo ${DAY}-MAY-$YEAR;;
      06) echo ${DAY}-JUN-$YEAR;;
      07) echo ${DAY}-JUL-$YEAR;;
      08) echo ${DAY}-AUG-$YEAR;;
      09) echo ${DAY}-SEP-$YEAR;;
      10) echo ${DAY}-OCT-$YEAR;;
      11) echo ${DAY}-NOV-$YEAR;;
      12) echo ${DAY}-DEC-$YEAR;;
    esac
    Note that there is no parameter vetting at all.

  3. #3
    Join Date
    Oct 2003
    Posts
    232

    can this be chanaged to ---

    can this be changed to run in such a way that

    at 2 am it gets the system date (month and day)

    122(jan23rd) and join with a batch file myfile 122 (on windows 2000)

    and for oct should be A22, noV should be B22 AND

    DEC Should be C22

    real catch is on 1st feb should be 131(jan 31st)

    THANKS
    Last edited by sjumma; 10-01-04 at 13:21.
    bigfoots

  4. #4
    Join Date
    Oct 2003
    Posts
    232

    Arrow Their is always a way out but one problem

    Here is how you can get it !!!!!!!!!!!!!!!!!!
    One problem how do i log in( from window) from a batch file , run the script and get the output of this from a file e.g ver.bat
    which i will run on dos ????


    #!/usr/bin/ksh
    TODAY=`date +'%m-%d-%Y'`

    # Get individual elements
    MONTH=`echo $TODAY | cut -d'-' -f1`
    DAY=`echo $TODAY | cut -d'-' -f2`
    YEAR=`echo $TODAY | cut -d'-' -f3`

    if [[ `expr $DAY + 0` -eq 1 ]]; then
    if [[ $MONTH -eq 1 ]]; then
    MONTH=12
    YEAR=`expr $YEAR - 1`
    else
    MONTH=`expr $MONTH - 1`
    fi

    cal $MONTH $YEAR | grep 31 1>/dev/null 2>&1
    if [[ $? -eq 0 ]]; then
    DAY=31
    else
    DAY=30
    fi
    else
    DAY=`expr $DAY + 0`
    DAY=`expr $DAY - 1`
    fi

    if [[ `echo $MONTH | wc -c` -eq 2 ]]; then
    MONTH=0$MONTH
    fi
    if [[ `echo $DAY | wc -c` -eq 2 ]]; then
    DAY=0$DAY
    fi
    # Previous day in the same format, without hyphens
    # NEW_DATE=$MONTH$DAY
    if [[ $MONTH -eq 10 ]]; then
    MONTH=A
    elif [[ $MONTH -eq 11 ]]; then
    MONTH=B
    elif [[ $MONTH -eq 12 ]]; then
    MONTH=C
    else MONTH=$MONTH
    fi
    filename=vercopy1
    NEW_DATE="$filename $MONTH$DAY"

    echo $NEW_DATE >ver.bat
    bigfoots

  5. #5
    Join Date
    Oct 2003
    Posts
    232

    Arrow Their is always a way out but one problem

    Here is how you can get it !!!!!!!!!!!!!!!!!!
    One problem how do i log in( from window) from a batch file , run the script and get the output of this from a file e.g ver.bat
    which i will run on dos ????
    i did write a batch file

    telnet servername
    username
    password
    ./verscirpt
    open ftp servername
    get ver.bat
    exit
    bye

    It does not take username and password


    #!/usr/bin/ksh
    TODAY=`date +'%m-%d-%Y'`

    # Get individual elements
    MONTH=`echo $TODAY | cut -d'-' -f1`
    DAY=`echo $TODAY | cut -d'-' -f2`
    YEAR=`echo $TODAY | cut -d'-' -f3`

    if [[ `expr $DAY + 0` -eq 1 ]]; then
    if [[ $MONTH -eq 1 ]]; then
    MONTH=12
    YEAR=`expr $YEAR - 1`
    else
    MONTH=`expr $MONTH - 1`
    fi

    cal $MONTH $YEAR | grep 31 1>/dev/null 2>&1
    if [[ $? -eq 0 ]]; then
    DAY=31
    else
    DAY=30
    fi
    else
    DAY=`expr $DAY + 0`
    DAY=`expr $DAY - 1`
    fi

    if [[ `echo $MONTH | wc -c` -eq 2 ]]; then
    MONTH=0$MONTH
    fi
    if [[ `echo $DAY | wc -c` -eq 2 ]]; then
    DAY=0$DAY
    fi
    # Previous day in the same format, without hyphens
    # NEW_DATE=$MONTH$DAY
    if [[ $MONTH -eq 10 ]]; then
    MONTH=A
    elif [[ $MONTH -eq 11 ]]; then
    MONTH=B
    elif [[ $MONTH -eq 12 ]]; then
    MONTH=C
    else MONTH=$MONTH
    fi
    filename=vercopy1
    NEW_DATE="$filename $MONTH$DAY"

    echo $NEW_DATE >ver.bat
    bigfoots

Posting Permissions

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