Need some help with compression / move script

Reply

Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Need some help with compression / move script

 
0
  #1
Aug 20th, 2007
Hi.

iv'e been looking around the web trying to find a suitable script to use with my hltv servers , unfortunately to no avail .

I'm just wondering if anyone here could perhaps help me out with a shell script to do what i need it to , i would be most grateful .


Here is what i need from the script :

Basically i run a lot of game servers ( may be able to offer whoever helps me something as im an admin of a very big server provider ) , so what i need from the shell script is for it to scan my hltv's directories for any .dem files , then i need it to compress them ( preferabbly in zip format) , then i need it to move the zipped files to a web directory , and then delete the original .dem files .

i did find a script that i thought would work which was this :

#!/bin/bash
HLDS=/home/dlmczt/hlds/czero/ #Working directory where demos are
REP=/var/www/html/czhltv/ #copying directory
#FORMAT="tar cvf"
#EXTENSION=tar
FORMAT=zip #Compression using ZIP
EXTENSION=zip #Associated extension
cd $HLDS
for files in `ls *.dem` do
$FORMAT $files.$(date +%s).$EXTENSION $files
echo "$files.$(date +%s).$EXTENSION compressed"
mv $files.$(date +%s).$EXTENSION $REP
echo "$files.$(date +%s).$EXTENSION moved"
rm $files
echo "$files deleted"
done;
echo "Demos are available in : $REP"


however all i got when i tried to run it was :

./zipped.sh: line 10: syntax error near unexpected token `$FORMAT'
./zipped.sh: line 10: ` $FORMAT $files.$(date +%s).$EXTENSION $files'


i tried using the full path to the interpreter and other things , but no joy .
if you think you can fix this problem then that would be great and probably save alot of time .

If not is there anyone who could make me a script ? , i can tell you any paths you need .
the distro is Fedora Core 4 .

Thanks in Advance.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #2
Aug 22nd, 2007
Help please , anyone ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Need some help with compression / move script

 
0
  #3
Aug 24th, 2007
Originally Posted by b1ue View Post

for files in `ls *.dem` do
should be:

for files in `ls *.dem`; do
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #4
Aug 24th, 2007
ok i'll try that now , thank you very much .
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #5
Aug 24th, 2007
excellent !! , that seems to have fixed that problem , just got a path problem to sort , but i think i can handle that , thanks very much
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #6
Aug 24th, 2007
OK , well it kind of works , but im getting this now :

adding: vswildfire-0706242023-de_cpl_fire.dem (deflated 83%)
vswildfire-0706242023-de_cpl_fire.dem.1187967195.zip compressed
mv: cannot stat `vswildfire-0706242023-de_cpl_fire.dem.1187967195.zip': No such file or directory
vswildfire-0706242023-de_cpl_fire.dem.1187967195.zip moved
vswildfire-0706242023-de_cpl_fire.dem deleted
Demos are available in : /var/www/html/cztv/



it does this on most files , and only actually moves some , although it zips all of them , but i had to move the ones it hadn't manually .

any ideas ?

Thanks again .
b1ue
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Need some help with compression / move script

 
0
  #7
Aug 24th, 2007
Try the following. It now 'moves' the file into the ZIP, verifies the integrity of the new archive, and it creates the ZIP file in the destination directory.

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. HLDS="/home/dlmczt/hlds/czero/" # Working directory where demos are
  4.  
  5. REP="/var/www/html/czhltv" # Copying directory
  6.  
  7. ARCHIVE="zip -T -m" # Compression using ZIP
  8. EXTENSION="zip" # Associated extension
  9.  
  10. cd $HLDS
  11.  
  12. for demfile in *.dem do
  13. $ARCHIVE $REP/$demfile.$(date +%s).$EXTENSION $demfile
  14. echo "$demfile moved into $REP/$demfile.$(date +%s).$EXTENSION"
  15. done

I made a few other readability changes. And remember, 'man zip' is your friend. Granted, it may seem like gobbledegook at first, but it *does* tell you what you can do with it.
Last edited by Fest3er; Aug 24th, 2007 at 1:26 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #8
Aug 24th, 2007
ok changed :

for demfile in *.dem do

to

for demfile in *.dem; do


and changed this path :
REP="/var/www/html/czhltv"

to

REP="/var/www/html/cztv"

and it all works !!!

only thing i want to do now is set it up on a cron job , so that it runs every say 20 minutes .


Thanks so much for this help , it's very much appreciated .
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 7
Reputation: b1ue is an unknown quantity at this point 
Solved Threads: 0
b1ue b1ue is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #9
Aug 24th, 2007
All Done and All Working .

Here is the final syntax incase anyone else finds it useful .


#!/bin/bash

HLDS="/home/dlmczt/hlds/czero/" # Working directory where demos are

REP="/var/www/html/hltv/cztv" # Copying directory

ARCHIVE="zip -T -m" # Compression using ZIP
EXTENSION="zip" # Associated extension

cd $HLDS

for demfile in *.dem; do
$ARCHIVE $REP/$demfile.$(date +%s).$EXTENSION $demfile
echo "$demfile moved into $REP/$demfile.$(date +%s).$EXTENSION"
done



And My Crontab entry to run every 30 mins is :

30 * * * * /home/dlmczt/hlds/autozip.sh > /dev/null


Thanks Guys , hope this helps others.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: psmawson is an unknown quantity at this point 
Solved Threads: 0
psmawson psmawson is offline Offline
Newbie Poster

Re: Need some help with compression / move script

 
0
  #10
Nov 21st, 2007
like the script blue,

would it be possible to get a script that could then remove the zipped up .dem files after they become 6months in age to keep down the disk space been used?

Would be a useful and great extra
Last edited by psmawson; Nov 21st, 2007 at 10:55 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC