Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2013
    Posts
    1

    Unanswered: script not working!

    Hello all,
    Please i need your help to check why my script is not working
    i'm a beginer in scripting... Your help will be highly appreciated. thank you in advance

    nawk command should search accross the files with names containing the date *$(day)* .

    here below is the script:

    get_date()
    {
    year=`date '+%y'`
    month=`date '+%m'`
    tod=`date '+%d'`
    today=tod-1
    day=$year$month$today
    }

    cd $mgw1path
    nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=5 s="pmProcessorCoreLoad" *$(day)* > /home/vfscript/scripts/proccessor_load/mgw1'+$(day)'.txt

    cd $mgw2path
    nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=5 s="pmProcessorCoreLoad" $(day)* > /home/vfscript/scripts/proccessor_load/mgw2'+$(day)'.txt

    get_date

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    The "day" variable is accessed before it is defined.
    Move "get_date", the last line, to the line after the close of the function.
    Code:
    get_date()
    {
    year=`date '+%y'`
    month=`date '+%m'`
    tod=`date '+%d'`
    today=tod-1
    day=$year$month$today
    }
    
    get_date 
    
    cd $mgw1path
    nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=5 s="pmProcessorCoreLoad" *$(day)* > /home/vfscript/scripts/proccessor_load/mgw1'+$(day)'.txt
    
    cd $mgw2path
    nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=5 s="pmProcessorCoreLoad" $(day)* > /home/vfscript/scripts/proccessor_load/mgw2'+$(day)'.txt

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713
    This will give you a '00' day:
    Code:
    get_date()
    ...
    today=tod-1
    ...
    In order to get the "yesterday's" day, you need to use something like this:
    Code:
    get_date()
    {
     day=$(TZ=CST+24 date '+%Y%m%d')
     year=`echo ${day}|cut -c1-4`
     month=`echo ${day}|cut -c5-6`
     today=`echo ${day}|cut -c7-8`
    }
    # ... Etc ...

    PS: If the "day" formula does not work on your OS, then try: Google.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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