jagomai Posted May 2, 2008 Report Share Posted May 2, 2008 Hi,I'm writing a simple batch script. I'm having trouble creating a correct variable however...I have a file named "_DateFile" that contains a date like this: 2005-05-05 . I wish to parse that file to get the date in it, and name a file in the script using that date. This is as far as I have gotten:Try to create variable from the command (grep will parse "_DateFile" for any line containing 2005 and output it):set olddate=´grep 2005 _DateFile´If I now type %olddate%, I do get the date that is stored in _DateFile. Success, I thought - but no. If I now want to create a file USING that old date, it will not work.For example:echo 1 > %olddate%.mydocument.docwill not create the file 2005-05-05.mydocument.doc. It creates a file called "grep". Hm.. It seems that Windows does not in fact store the *output* of the command in olddate, but the command itself.. If I do echo %olddate%, I get:grep 2005 _DateFileDoes anybody know how to make the Windows variable remember the *value* outputted from a command - and not the command itself?Thanks alot! Quote Link to comment Share on other sites More sharing options...
leadfalcon Posted May 2, 2008 Report Share Posted May 2, 2008 I dont know if this will help you buy why not just put the code that generates the _DateFile value in the first place into your batch script? So it looks something like this:#Generate Date Code Here#Continue your batch code Hereecho 1 > %olddate%.mydocument.doc Quote Link to comment Share on other sites More sharing options...
jagomai Posted May 2, 2008 Author Report Share Posted May 2, 2008 I dont know if this will help you buy why not just put the code that generates the _DateFile value in the first place into your batch script? So it looks something like this:#Generate Date Code Here#Continue your batch code Hereecho 1 > %olddate%.mydocument.docNah, I can't do that because I won't know what date to put into the _DateFile.. The value in the _DateFile will be created sometime (we don't know when) before I run the script I write now.I've got it all figure out, except for this last piece... I did some research, and found this page, but it didn't contain any information about doing what I want.. Maybe SET isn't the command I need at all?Anybody know anything about these kinds of stuff? Quote Link to comment Share on other sites More sharing options...
Scarecrow Man Posted May 2, 2008 Report Share Posted May 2, 2008 Good info herehttp://www.student.northpark.edu/pemente/sed/bat_env.htm Quote Link to comment Share on other sites More sharing options...
jagomai Posted May 4, 2008 Author Report Share Posted May 4, 2008 Good info herehttp://www.student.northpark.edu/pemente/sed/bat_env.htmThanks Scarecrow Man, that did the trick. For all future seekers, here are my final (but sketchy results):Script 1, upload files to server:This packs folder 1 and folder 2 into a rar, uploads the rar and the datefile unto the server.REM Create archive(s) of Folder 1 and Folder 2, but make each rar-file maximum 50MB large.rar a -ep1 -r -v50176 %date%.MyData.rar "PathToFolder1" "PathToFolder2"ECHO ENCRYPT the file...gpg --output %date%.MyData.rar.gpg --recipient MyKey --encrypt %date%.MyData.rarECHO DELETE the unencrypted file...del %date%.MyData.rarECHO UPLOAD the file... (enter password)echo %date% > _DateFilecurl --user [email protected] --ftp-ssl-control --insecure --ftp-ssl-reqd --sslv3 --upload-file {%date%.MyData.rar.gpg,_DateFile} PathToUploadFilesOnServer/ECHO DELETE the local encrypted file...del %date%.MyData.rar.gpgdel _DateFileENDScript 2, download latest snapshot of files from the server:This downloads the latest uploaded RAR archive from the server.@ECHO OFFREM Download DateFile that has only the latest date inside of it:curl --user [email protected] --ftp-ssl-control --insecure --ftp-ssl-reqd --sslv3 --output _DateFile PathTo/_DateFileREM Get the date out of the file and make it a variable:awk "/2008/ {print \"set latestdate=\" $1}" _DateFile >tmp_.batcall tmp_.batecho The latest date of the file on server is (according to datefile): %latestdate%echo Continue with download? If not press CTRL-C. Otherwise ENTER.pauseREM Use the variable to get the latest snapshot:curl --user [email protected] --ftp-ssl-control --insecure --ftp-ssl-reqd --sslv3 --output %latestdate%.MyData.rar.gpg PathTo/%latestdate%.MyData.rar.gpgREM Decrypt, unpack, etc:gpg --output %latestdate%.MyData.rar --decrypt %latestdate%.MyData.rar.gpgREM Clean up encrypted file.del %latestdate%.MyData.rar.gpgREM Unpack.rar x %latestdate%.MyData.rar _Downloaded\MyData\REM Clean up archive.del %latestdate%.MyData.rarENDMaybe I'll merge them later into one script. I run the scripts from the same folder as I have the executables (gawk, gpg-to-go, rar and curl - all of which are downloadable from the Internet - well, except for rar which you have to buy if you want to be able to create split archives).So I have one folder with everything related to the scripts.Hm, as a side note, the gpg-to-go isn't really important if you don't care about the privacy of the files uploaded.. However, if you script it like this you will never notice it is encrypted on the server at all (I have no password for my secret key -> no need for entering passwords), and the you will be safe from the prying eyes of the Big Brother Internet Overlords.A second side note: Even though I have the line for splitting the rar archives into 50MB pieces, the files I'm uploading are always smaller. The script will not work for more than one file (I'll have to amend it later for that to work... With loops and internal counters somehow, (curl can't take *.rar ..) well that's a later problem)Thanks for the help guys, problem solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.