Click to See Complete Forum and Search --> : Compressing Files Script Help


Buzzpud
02-08-2006, 03:58 PM
Hi All

I have wrote a script which copies files with the dem extension to an ftp site for peeps to download. The only problem is the files can be very large and I dont know how to zip the files individually in a script so that are moved individually zipped up.
The script below moves them individually up to my ftp site:

#!/bin/sh
cd cs16_13/cstrike/
mv *.dem /home/andy/csdemstore/
cd /home/andy/
ncftpput -u user@ftpsite -p ******** directory.ftpsite /Counter-Strike csdemstore/*.dem

The script moves up to four files at a time but they can be about 80 to 100 meg in size each.

Does anyone know a script that compresses each one individually but keeps them seperate so you have four zipped dem files.

Any help appreciated????

Buzzpud

ph34r
02-08-2006, 05:26 PM
#!/bin/sh
cd cs16_13/cstrike/
for i in `ls -1d *dem`
do
cp $i $.tmp
gzip $i
mv $i.tmp $i
done

mv *.dem /home/andy/csdemstore/
cd /home/andy/
ncftpput -u user@ftpsite -p ******** directory.ftpsite /Counter-Strike csdemstore/*.dem.gz


Added the for..in.. loop and changed the extension on files to upload. Could be made fancier by usign a touch file adn only uploading new files, etc.

bwkaz
02-08-2006, 08:32 PM
YIKES! Useless Use of Backticks (http://www.ruhr.de/home/smallo/award.html#backticks)! ;)

#!/bin/sh
cd cs16_13/cstrike/
for i in `ls -1d *dem`
do
cp $i $.tmp
gzip $i
mv $i.tmp $i
done

mv *.dem /home/andy/csdemstore/
cd /home/andy/
ncftpput -u user@ftpsite -p ******** directory.ftpsite /Counter-Strike csdemstore/*.dem.gz (There are also a few extra processes there that don't need to be.) Try something like:

for i in *dem
do
gzip -c <"$i" >"$i.gz"
done

mv *.dem /wherever
cd /wherever
ncftpput -whatever (The -c option to gzip says "take your input from stdin, and write your output to stdout". Redirections tell the shell to make gzip's stdin come from *.dem, and make its stdout go to *.dem.gz, thus doing exactly what it looks like you want. The quotes, plus the "for i in *dem", make it work even if any of the *dem files have spaces or newlines in their names.)

Buzzpud
02-09-2006, 11:57 AM
Thanks I will try what you have posted....

Buzzpud
02-09-2006, 01:52 PM
Okay

I have got as far as having the *.dem files zipped seperately and a file called $.tmp being created in the same directory as the zipped files but then I get the error message below for each zipped file ( 2 in this case ):

mv: cannot stat `anyfile1.dem.tmp : No such file or directory
mv: cannot stat `anyfile2.dem.tmp : No such file or directory

I am using ph34rs original script as I couldnt get bwkaz's one to work.

Any ideas on this and what mv $i.tmp $i does exactly?????

Thanks

Buzzpud

Buzzpud
02-09-2006, 03:49 PM
Its ok now I realised what the problem was it was a typo sorry dudes its working ok now and thanks again.