LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   auto creating 3 lists using filetypes (https://www.linuxquestions.org/questions/linux-newbie-8/auto-creating-3-lists-using-filetypes-455434/)

mrgreaper 06-16-2006 10:43 AM

auto creating 3 lists using filetypes
 
ok after you guys helped me with random map script it got me thinking of other possible uses to make life easier on the server and i renebered theres 3 identicle list files that i have to hand type and add to everytime i add maps to the server

heres what i`d like a script to do
scan the /home/mrgreaper/srcds_1/cstrike/maps/ folder for all *.bsp and all *.nav file formats
create a list of all files that have both *.bsp and *.nav
remove the extensions and dump into 3 text files replacing the prevouse contents

Code:

#!/bin/sh

mapdir=/home/mrgreaper/srcds_1/cstrike/maps
maps=($(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;))

navs=($(find $mapdir -type f -name "*.nav" -exec basename "{}" .nav \;))[/CODE]

the above im guesing at using the example someone posted when i needed a random map

then i need some way to compare the two files since we have already removed the extensions then i would want to keep 1 of what ever duplicates in the lists
so if list one was
de_dust
de_rats
cs_office

and list 2 was
de_dust
cs_office

then the duplicates would be de_dust and cs_office so i would want those two names to in my list like so
list3;
de_dust
cs_office

the returns after each name are also important
Code:

List3= compare part of the script i have no idea
then would need to replace the contents of the three files
Code:

cd /home/mrgreaper/srcds_1/cstrike
echo $List3 maplist.txt
echo $list3 mapcycle.txt
cd /home/mrgreaper/srcds_1/cstrike/cfg/mani_admin_plugin/
echo $List3 votemaplist.txt

i think i may need to get a book on this sh console thing lol

binary_y2k2 06-17-2006 03:15 AM

You can use something like
Code:

list3="$(echo -e "$maps$navs"|sort -d|uniq -d)"
to get that list.
You also need to replace the 1st and "(" and last ")" with qutes from the maps and navs variables or you'll get a "(" on the 1st file and a "(" on the last one.
Also wnen you want to put the list in to a file use
Code:

echo -e "$list3"
or you won't get the reterns.

mrgreaper 06-17-2006 08:25 AM

i think im doing it wrong
Code:

#!/bin/sh

mapdir=/home/mrgreaper/srcds_1/cstrike/maps
maps=($(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;))
navs=($(find $mapdir -type f -name "*.nav" -exec basename "{}" .bsp \;))
list3="$(echo -e "$maps$navs"|sort -d|uniq -d)"

echo -e "$list3" /home/mrgreaper/test.txt

it takes a break for 30 secs when run (500 maps in the map folder about 300 with navs"
then displays on the screen

/home/mrgreaper/test.txt

the file test.txt however is blank :(
any ideas where im going wrong?

binary_y2k2 06-17-2006 10:34 PM

You havent done the redirect right,
the last command needs to be
Code:

echo -e "$list3" > /home/mrgreaper/test.txt
insted if "echo -e "$list3" /home/mrgreaper/test.txt"

mrgreaper 06-18-2006 07:09 AM

changed the last line as above but it still just an empty test.txt file
i have tried chmod 777 it as well not sure it would make a difference ....and it didnt :(
wish i knew what is wrong with it

binary_y2k2 06-18-2006 07:40 AM

1st change
Code:

maps=($(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;))
to
Code:

maps="$(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;)"
and on the navs variable too. If that still won't work then run this script
Code:

#!/bin/sh

mapdir=/home/mrgreaper/srcds_1/cstrike/maps
maps="$(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;)"
#echo $maps
navs="$(find $mapdir -type f -name "*.nav" -exec basename "{}" .bsp \;)"
#echo $navs
list3="$(echo -e "$maps$navs"|sort -d|uniq -d)"

echo -e "$list3"

If you dont get any output uncomment "echo $maps" and "echo $navs" to see what they are being ser to.

mrgreaper 06-18-2006 07:35 PM

Quote:

Originally Posted by binary_y2k2
1st change
Code:

maps=($(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;))
to
Code:

maps="$(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;)"
and on the navs variable too. If that still won't work then run this script
Code:

#!/bin/sh

mapdir=/home/mrgreaper/srcds_1/cstrike/maps
maps="$(find $mapdir -type f -name "*.bsp" -exec basename "{}" .bsp \;)"
#echo $maps
navs="$(find $mapdir -type f -name "*.nav" -exec basename "{}" .bsp \;)"
#echo $navs
list3="$(echo -e "$maps$navs"|sort -d|uniq -d)"

echo -e "$list3"

If you dont get any output uncomment "echo $maps" and "echo $navs" to see what they are being ser to.



i`m a moron
Code:

navs="$(find $mapdir -type f -name "*.nav" -exec basename "{}" .bsp \;)"
should read

Code:

navs="$(find $mapdir -type f -name "*.nav" -exec basename "{}" .nav \;)"
of course it was displaying as blank i wasnt removing the .nav extension so there was no duplicate names for it to list as cs_office is not the same as cs_office.nav


worked perfectly with above changes thnx guys
is there a site i can see a list of commands with detailed descriptions i looked at the one on this site the wiki but it discribes non of the echo commands that you guys shown me ?

the one last thing i need to do with the script is to make it spill a list of unique names

so using my original example
Quote:

so if list one was
de_dust
de_rats
cs_office

and list 2 was
de_dust
cs_office
then navsneeded.txt would just be
de_rats

now its clearly to do with ;
list4="$(echo -e "$maps$navs"|sort -d|uniq -d)"
the red bit

binary_y2k2 06-19-2006 07:53 AM

To be fair, I should have seen that line too, so your not the only moron :p
There are sites with lists of commands and descriptions, and there's always the man pages "man (command)", because there are a lot of linux commands and they change from distro to distro I'm not sure you'll find a site with every command on it. But there are sites with man pages indexed by name like [http://manpages.debian.net/by_man.html] but you can spend DAYS looking thru all of them. You'll want some tutorials in scripting, eg. search google for "bash scripting" and things like "howto (what your trying to do) bash", chance is you'll find something helpful.

Now about that last command you want to run.
"list4="$(echo -e "$maps$navs"|sort -d|uniq -d)" would turn in to "list4="$(echo -e "$maps$navs"|sort -d|uniq -u)"
take a look at "uniq --help" and "man uniq" for more options, it's a nice little command to know about.

chrism01 06-20-2006 01:41 AM

Here's 3 links you may find useful:
http://rute.2038bug.com/index.html.gz
http://www.tldp.org/LDP/abs/html/index.html
http://www.faqs.org/docs/bashman/bashref.html#SEC_Top

timmeke 06-20-2006 03:30 AM

http://about.linux.com and
http://howtos.linux.com
seem nice too.

mrgreaper 06-20-2006 06:35 AM

thank you gotta sort my samba problem out then i shall have a read of those sites

mrgreaper 06-20-2006 07:09 PM

just how advanced can you get with this!

the purpose of the above script is because the game i host for my mates uses bots
now they need a nav file associated with every map
so for the bots to play cs_office there needs to be cs_office.bsp and cs_office.nav
if cs_office doesnt exist it creates it slowly between 20minutes and 2 hours sometimes longer and often crashing the server
so i download the map on my pc load up cstrike using nav file editing button cfgs and edit/create one my self then copy the nav file acoss and xtract the map file to the server (maps have material files sound files model files allsorts or just bsp files)

any way what im curiouse about is this possible ;

say the structer of the cstrike folder (the draws im interested in at anyrate)
cstrike
--materials
---levelname1
---levelname2
---levelname3
---etc etc
--sounds
--maps
---soundcache
---graphes
--models

could a script be made that would look at the local /cstrike folder look at the cstrike folder on a network pc and if it finds any files on the network pc it copys them to the relevent folder on the local pc

for example say i download onto my pc a map called cs_office nd that contains the following files / folders

--materials
---cs_office
----office.vmf
----moniter.vmf
--sound
---speakers.mp3
---vending.mp3
---someother.mp3
--maps
---cs_office.bsp
---cs_office.nav
---cs_office.txt
---soundcache
---cs_office.cache

and ran the script would it realise the above folders where different and even that a new folder had been created and then copy the files to the local folders so the server had the same files?
i thnk perhaps im asking to much but i have been plesently surprised so far so remain optimistic

chrism01 06-20-2006 09:10 PM

rsync is your friend ....

timmeke 06-21-2006 01:49 AM

or "wget" if the remote machine has an FTP access.

mrgreaper 06-21-2006 06:40 AM

rsync looks way above my competent computing level :(
i could easily install a windows ftp server on my main pc
how would i use wget to copy any file changes across to the sever and make sure they go to the right folders?
i did have a quick read of the wget manual manly the examples but couldnt see anything right

i`m gussing its not as simple as wget --ftp-user=user --ftp-password=password my.ftp.ip/maps/*.* /home/mrgreaper/srcds_1/cstrike/maps/*.*

timmeke 06-21-2006 07:17 AM

Check out the "mirror" option. This may do the trick.

However, I typically use something like:
Code:

cd /home/mrgreaper/srcds_1/cstrike/maps/
wget -N -r -l inf --no-parent -nH -a some_logfile --ftp-user=some_user --ftp-password=some-password ftp://my.ftp.ip/maps/

When using wget in recursive mode (-r), you don't need to specify "*.*". It'll search through the directory structure recursively.
-N makes it look at timestamps on files (in addition to filesizes) to download only updated and new files.
You may want to add options like -A '*.nav,*.bsp' to get only the .nav and .bsp files.

Just try it. You'll see that it's fairly easy to use and has plenty of options. As I said, setting up the FTP server (with sufficient security) is usually the hard part...

mrgreaper 06-21-2006 10:36 AM

Quote:

Originally Posted by timmeke
Check out the "mirror" option. This may do the trick.

However, I typically use something like:
Code:

cd /home/mrgreaper/srcds_1/cstrike/maps/
wget -N -r -l inf --no-parent -nH -a some_logfile --ftp-user=some_user --ftp-password=some-password ftp://my.ftp.ip/maps/

When using wget in recursive mode (-r), you don't need to specify "*.*". It'll search through the directory structure recursively.
-N makes it look at timestamps on files (in addition to filesizes) to download only updated and new files.
You may want to add options like -A '*.nav,*.bsp' to get only the .nav and .bsp files.

Just try it. You'll see that it's fairly easy to use and has plenty of options. As I said, setting up the FTP server (with sufficient security) is usually the hard part...

i`m in the process of getting ready for work so it will be at least 16 hours till i get to try it more likely more :(

i assume with the command above it would check the folders inside maps as well?
for example the sound cache and graph folders and if it finds any new files in them it would copy them to the relevent folder on the local machine

so if we got cs_office.cache added to soundcache folder inside the map folder it would see the new file on the ftp look at the soundcache folder within /home/mrgreaper/srcds_1/cstrike/maps/ on the local machine realese the local machine didnt have it and create it?

basicly would it keep the folders on the local machine up to date in full so if new folders are created both they and there content is copyed to the server ?

i know im asking a lot, i`m sorry to pester i just find the manual pages are written for more competent users then me, your help and assistence is as always extremely regarded thank you

mrgreaper 06-22-2006 10:48 AM

cd /home/mrgreaper/srcds_1/cstrike/
wget -N -r -l inf --no-parent -nH -a some_logfile --ftp-user=some_user --ftp-password=some-password ftp://my.ftp.ip/maps/

worked a treat again thanks guys

timmeke 06-23-2006 04:24 AM

Yep, it'll check for subfolders too, thanks to "-r -l inf" (-r makes it recursive - ie looking through subfolders, -l inf makes it search through all levels (an "infinite" number of levels) of subfolders).
It will create files and subfolders as needed.

You can even toy around with options like -X to exclude certain files or subfolders (based on wildcard patterns like "*.cache"). I often also use -A option to limit the downloads to only certain files, ie -A "*.ZIP" to get only *.ZIP files.

--cut-dirs=n makes wget cut off "n" directories from the target path.
ie: if your target is ftp://my.ftp.ip/maps/, then -nH will make wget not create a folder called "my.ftp.ip", --cut-dirs=1 will make it not create a "maps" folder (but it will create subfolders of "maps" if needed). -nd should prevent wget from creating any directories.

Should the download be interrupted, just add the "-c" option to make wget continue the file downloads that were interrupted.

--mirror can be a useful shorthand for "-N -r -l inf --no-remove-listing" in your case. Only difference to your command is the "--no-remove-listing" option (makes wget not throw away the list of downloaded files).


All times are GMT -5. The time now is 06:24 AM.