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/*.*


All times are GMT -5. The time now is 08:16 PM.