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.

Help please , anyone ? :(


for files in `ls *.dem` do

should be:

for files in `ls *.dem`; do

ok i'll try that now , thank you very much .

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 :)

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

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.

#!/bin/bash

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

REP="/var/www/html/czhltv"      # 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

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.

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 .

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.

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

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

Of course it is possible. Don't be ridiculous.

Sorry, I couldn't resist stealing a line from an old TV sitcom.

On a GNU system, the following script should work.

#!/bin/bash
 
REP="/var/www/html/hltv/cztv" # Copying directory
TMP_PATTERN="/tmp/cztv_pattern"
 
# First, create a file dated 6 months in the past
touch -d "6 months ago" ${TMP_PATTERN}

# Now find all files in the target directory that are not newer
#   than the pattern, and delete them. Do NOT descend into
#   sub-directories (if any)
find ${REP}/* -prune  ! -newer ${TMP_PATTERN} -exec rm -f {} \;

# Finally, delete the pattern
rm -f ${TMP_PATTERN}

Warning: this script is not tested. I'm fairly certain the command syntax is correct, though. Test it thoroughly before deploying it!

N

Do you by chance live in the FT Lauderdale area?

commented: Nobody cares -7

Do you by chance live in the FT Lauderdale area?

:( Please specify.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.