Hi all,
I have a file\(Say x\) and need to zip using gzip with the date&Timestamp\(Something like x01012007.......\) . Can you please tell me the command.
Thanks
Hi all,
I have a file\(Say x\) and need to zip using gzip with the date&Timestamp\(Something like x01012007.......\) . Can you please tell me the command.
Thanks
gzip -c x > x"$(date +%Y%m%d)".gz;
# optional:
rm x
ARCHIVEDIR="archive/"
WEEKDAY=date +"%u"
if [ WEEKDAY -eq 7 ]
then
WEEKDAY=0
fi
DAY=`date +"%a"`
DD=`date +"%d"`
#DAY=`date +"%d"`
MONTH=`date +"%m"`
YEAR=`date +"%Y"`
TOKEN=`date +"%b %d"`
echo $TOKEN
# Get previous date.
DD=`expr $DD - 1`
case $DD in
0)
MONTH=`expr $MONTH - 1`
case $MONTH in
0)
MONTH=12
YEAR=`expr $YEAR - 1`
;;
esac
DD=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`
esac
MONTH=`cal $MONTH $YEAR | grep . | fmt -1 | head -1 | cut -c 8-10`
TOKEN=$MONTH" "$DD
# Get name of the file to be archived.
echo $TOKEN
echo $DIR
echo $FILE
FNAME=`ls -l $DIR | grep -e $FILE | grep -e $MONTH" "$DD | cut -c 58-`
echo $FNAME
# Remove prev file from archive directory having same date.
CURRDIR=`pwd`
cd $ARCHIVEDIR
rm $ARCHIVEDIR$FILE.???"_"$DD* 2> /dev/null
cd $CURRDIR
# Archive the file
gzip -c $DIR$FNAME > $ARCHIVEDIR$FILE"_"$DD"_"$MONTH".Z"
You can try some thing like the given above !!