shell scripting
Hello folks.
Long time no post. Ive googled and googled but this is all to new for me so im kind of not entirely sure what i need to. Anyways. I manage a HLTV server which records demos of half life based games. Linux based (Fedora) The server records them and puts them in a .dem extension here is an example of the file names it outputs the recordings to x-0606061517-dod_saints.dem x-0606061542-dod_saints.dem (x is what we give, the nubmers are a timestamp and the dod_saints is a map name) for those that dont know what I am on about its a recording a match on a computer game called Day of Defeat when the recordings have completed its a right pain a the but to do zip them up, move them to web server etc. What i want to do is to build a script to do it for me and at the same time learn some .sh scripting. here is what i want to do 1. script searches /hltv/dod for *.dem and returns the folder. 2 2. I then want one of the files to be returned into a variable (ill explain why) 3. I the want to move the results of the find to /wwwdocs/13-demos 4. Then want to zip up the .dem files in /wwwdocs/13-demos and name the zip from the name in the variable i declared in step 2 so i end up with this: /wwwdocs/13-demos/x-0606061542-dod_saints.dem.zip 5. I then want to delete the .dem files in /wwwdocs/13-demos and /hltv/dod now I can do all this manually but putting it into a script is a little beyond me Now im not looking for people to code this for me or anything. Linux shell scripting is as new to me as meat is to bugs bunny. Im looking for decent online resources, code hints, tips etc how I can do this. I can put everything into cron, I can do the 5 steps manually. Its just how do I loop through the file folders. see if *.dem can be found, put the last one returned into a variable etc Thanks for your time and efforts to help me with this. Also where do i go to make a donation here? Ive asked questions in the past but never returned very much back. I rarley have time to post on my own websites. ahhh never mind about the donations. I found it. Hope it helps. |
Just to get you started, you'll probably want to use something like the following loop:
Code:
#! /bin/bash |
Applaud your efforts but let me encourage you to skip the shell scripting and go straight for perl or python. It's a lot easier, more fun, and you'll make more money probably. I know lots of sysadmins who are "still" trying to learn "shell scripting", whatever that is. The rest of us have moved on. :)
So building on what spirit receiver said, have a look at the output from: find2perl /hltv/dod -type f -name "*.dem" and then delve into the ever present and extremely useful File::Find module. You will have something robust built in no time. |
Many thanks for your replies
spirit receiver: that has been a fantastic help and has given me a good start to acheive my target eltbee: I never really thought about perl/python to be honest for this task. Ive looked at perl in the past for web use, but didnt get very far. I will have a search about and see if its going to be better use to me. i got to go off to work now (oh joy) so ill have a play tonight :D Thanks again! |
spirit receiver: Thank you so much for that little snippit.
I have a working script now that does everything I need. Addmitingly its pretty bastic at the moment. But it works like a charm! Here is my final code Code:
#! /bin/bash i can only get better now. |
Congratulations, looks fine to me. I only want to mention that special characters (like whitespace) in filenames will break your script, you could change that using the internal variable IFS and by placing double quotes around the names where appropriate.
|
All times are GMT -5. The time now is 12:52 PM. |