Operating System - HP-UX
1825001 Members
2617 Online
109678 Solutions
New Discussion юеВ

How to get the filename_xxx.tgz to 2003-11-03-235900.tgz

 
Ho_5
Advisor

How to get the filename_xxx.tgz to 2003-11-03-235900.tgz

hi all,

A shell script question.
In my system, everyday 4 log files will be generated.
2003-11-03-235900.log
2003-11-03-235900.logaaaa
2003-11-03-235900.logbbb
2003-11-03-235900.logcc

I want to tar/gzip them.
tar cvf - $FWDIR/log/20??-??-??-2359??.log* | gzip -9 > /tmp/filename_xxx.tgz.

My question is how can I get the filename_xxx.tgz into 2003-11-03-235900.tgz???

Also after the compression I want to ftp the 2003-11-03-235900.tgz to the ftp server.
I had made some kinds of script like this, do you think it will works??

**************************************************************
more /scripts/ftp_script.sh
#!/usr/bin/sh
ftp -n -v << EOF > /tmp/filename_xxx.ftplog
open hostname
user admin password
bin
cd $FWDIR/log/
lcd /backup/
put *.tgz
bye
EOF

STATUS=`grep Complete /tmp/filename_xxx.ftplog`
if [[ $STATUS == "Complete" ]]; then
rm filename_xxx.log*
ERROR=0
else
ERROR=1
fi
exit $ERROR

**************************************************************


Thanks

//john
3 REPLIES 3
Bryan D. Quinn
Respected Contributor

Re: How to get the filename_xxx.tgz to 2003-11-03-235900.tgz

Hey John,

For the renaming of the file I would do something like this in your script:

DATE=`date "+%Y-%m-%d-"

tar cvf - $FWDIR/log/20??-??-??-2359??.log* | gzip -9 > /tmp/${DATE}235900.tgz

Hope this helps!
-Bryan
Bryan D. Quinn
Respected Contributor

Re: How to get the filename_xxx.tgz to 2003-11-03-235900.tgz

Hey John,

Let me correct something:

What I posted previously:

DATE=`date "+%Y-%m-%d-"

Should have been this:

DATE=`date "+%Y-%m-%d-"`


-Bryan
Joris Denayer
Respected Contributor

Re: How to get the filename_xxx.tgz to 2003-11-03-235900.tgz

John,

With a 2line script it is pretty simple.

FILENAME=`ls 20??-??-??-2359??.log | cut -f 1 -d "."`

tar cvf - $FWDIR/log/${FILENAME}.log* | gzip -9 > /tmp/$(FILENAME}.tgz


Of course, better would be to create the variable FILENAME in function of an argument of your little script. Where that argument is the date.

Something like this

FILENAME=`ls ${1}-235900.log | cut -f 1 -d "."`
tar cvf - $FWDIR/log/${FILENAME}.log* |gzip -9 > /tmp/$(FILENAME}.tgz


If you call your script "ziplog", then you can execute
./ziplog 2003-11-03


Hope it inspires

Joris
To err is human, but to really faul things up requires a computer