For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2005 > CGI changes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author CGI changes
Kamalraj Singh Madhan

2005-10-20, 4:00 am

Hi Guys,
I have a cgi which automates the task of zipping up a complete
directory and its sub directories:

echo "Content-type: text/html"
echo ""
echo "<html><head></head>"
echo "<body>"
echo "Building tar file...<br />"
echo "<tt>"
cd /var/www/html/
for type in test;
do
filen=3D${type//\//-}
echo "<br /><b>Building ${filen}.tgz</b> <br />"
tar cvfz files/${filen}.tgz --sparse ${type}
echo "<br />"
echo "See <a href=3D'/files/${filen}.tgz'>/files/${filen}.tgz</a>. <br
/>"
done;
echo "</tt><br />"
echo "Done."
echo "</body></html>"=20


Now I want to add the current date to the name of the zipped up file
i.e. to the variable named 'filen' in the above script...=20

Is there any date function in shell scripting which can solve this
problem? Kindly suggest.=20

Regards
Kamal =20
Xavier Noria

2005-10-20, 4:00 am

On Oct 20, 2005, at 9:24, Kamalraj Singh Madhan, Noida wrote:

> Now I want to add the current date to the name of the zipped up file
> i.e. to the variable named 'filen' in the above script...
>
> Is there any date function in shell scripting which can solve this
> problem? Kindly suggest.


Yes, you can do something like this:

today=`date "+%Y-%m-%d"`
backup=~/tmp/backup-${today}.pax

-- fxn

PS: I guess you were asking this in a mailing list about Perl in case
some Perl one-liner could solve it the way date(1) does, but the
idiomatic solution in sh is date(1).
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com