New here? Register and read our Community Rules. Accounts are approved by hand.

Wget with date variable

TH_GeorgeTH_George Member
edited April 2016 in Help

Hello,

I would like some help from anyone that knows a bit more about unix commands.
I am trying to set a cron with wget command to retreive a file that will be generated automatically everytime that is requested.

The file is created in this format --> 00000_year_month_date.xml
where year,month and date are numbers of the exact moment the wget takes place.
Also month for example is plain 4 for April and not 04.

Is there a way to make the wget use variables in the place of year,month and date to make this happen?

Thank you for your time.

George

Comments

  • blackblack Member
     wget location -O "`date`.xml" 

    You can use +% after date to specify your format.

  • Thank you for taking the time to reply.

    What I mean is this file name is in the "location" section

    So I want to do

    wget http://samplesite.com/00000_'date'.xml -O "savedfile.xml"

    Will the date variable work in the "location" part ?

  • blackblack Member

    That would be

     wget "http://somesite/00000_`date`.xml" 

    the -O option is tell it to save the file as a different name. I thought you meant you want to save it as a special name, not grab a special named file so -O might not even be needed.

  • Haven't tried it yet, but the date format could be something like

    date +%Y_%-m_%d

    The %-m is a GNU date feature that removes the zero-padding from the month.

Sign In or Register to comment.