piping a file name from a file into gzip
Posted on 2008-10-14
I am working on a cmd file that will do the following. Take the most recent file in a directory and gzip it up into a specific zip name.
I have a few of the pieces however I am stuck on trying to figure out how to pass / pipe the file name as input to gzip.
Here is what I have so far.
I was trying to break this down into testable pieces - and tried a few different things, in theory I could/would like to combine the commands back into one file.
dir c:\temp /a:-d /o-d /b > dirfiles.txt
head 1 dirfiles.txt
I have a file called head.bat which I found on the web to mimic linux head. It looks like this and seems to be working correctly
if [%1] ==  goto usage
if [%2] ==  goto usage
SET /a counter=0
for /f "usebackq delims=" %%a in (%2) do (
if "!counter!"=="%1" goto exit
set /a counter+=1)
echo Usage: head.bat COUNT FILENAME
In dirfiles.txt I have the following:
as I typed this I realized that the /b command on the dir that created the above text file resulted in the file name in the not having the full path to find it - that is a problem although when I manually edited the file to include it I was no better off.
then I was at this point as I was trying to figure out what was wrong I tried
gzip < head 1 dirfiles.txt
and then I tried creating a cmd called getrecentfile.cmd
head 1 dirfiles.txt
gzip < getrecentfile.cmd
so a couple of things I need to be able to specifiy/hardcode the .gz name - like dbzip.gz because once it is zipped I have another script which is already working which will ftp it to a site that is expecting a sepcific file name.
Allso the path to the file that is in the directory i sorted is in a different location then the script doing the the process so the full path will necesarry - either via the dir command or as a static part of the name/variable creation that is passed to gzip - the location will not change.
I am basically nightly looking for the most recent database dump and trying to zip it up and ftp it to another location in an automated way.
thanks for you help!