dynamic names for .tar.gz files?

Hi All,

I have a requirement to zip and compress files with dynamic names (which includes date and time component in their names) needs to be compressed with same name.

for example I have a file T.30.SLS_ORD.SO.27.2_2_2.20080623.041415.dat which needs to archived as T.30.SLS_ORD.SO.27.2_2_2.20080623.041415.tar.gz.

I tried all options but no use. Can some one worked on these please let me the script or options to achive this.

Thank you very much in advance.

Regards,
Srinivas

You would have to tell use what parts of the filename are variable but the date and time parts are easy. If this is only a single file then I am not sure why you would TAR it ( tar does nothing but put a wrapper around a single file).

FILE=T.30.SLS_ORD.SO.27.2_2_2.
DATE=`date +%Y%m%d`
TIME=`date +%T|tr -d:`
NEWFILE="$FILE$DATE$TIME"

echo "new file is called $NEWFILE"
#tar up the file
tar cvf $NEWFILE.tar $NEWFILE
#Zip it up
gzip $NEWFILE.tar