bash script for archive by month-year

Discussion in 'Programming/Scripts' started by tim lee, Mar 9, 2015.

  1. tim lee

    tim lee New Member

    Hi, I'm using redhat / centOS and have been trying to create a bash script to gtar my daily backup files by month-year. I had some problems with file naming as in going to the last month of the year, instead of 2014-12 it becomes 2015-12.
    Can someone help to identify my mistake?

    #!/bin/bash
    MONTH=$(date +%m -d "1 day ago")
    YEAR=$(date +%G)
    cd /tmp/script/logs
    tar -czvf Notifier.log.$YEAR-$MONTH.tar.gz Notifier.log.*
     
  2. sjau

    sjau Local Meanie Moderator

    Not sure what you're actually trying to do.
     
  3. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    filedate=`date +%G-%m --d "1 day ago"`
     
  4. sjau

    sjau Local Meanie Moderator

    Don't use backticks. Better use var=$( some command )
     

Share This Page