LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2006, 10:43 AM   #1
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Rep: Reputation: 15
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
 
Old 06-17-2006, 03:15 AM   #2
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
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.
 
Old 06-17-2006, 08:25 AM   #3
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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?
 
Old 06-17-2006, 10:34 PM   #4
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
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"
 
Old 06-18-2006, 07:09 AM   #5
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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
 
Old 06-18-2006, 07:40 AM   #6
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
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.
 
Old 06-18-2006, 07:35 PM   #7
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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
 
Old 06-19-2006, 07:53 AM   #8
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
To be fair, I should have seen that line too, so your not the only moron
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.
 
Old 06-20-2006, 01:41 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,347

Rep: Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365
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
 
Old 06-20-2006, 03:30 AM   #10
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
http://about.linux.com and
http://howtos.linux.com
seem nice too.
 
Old 06-20-2006, 06:35 AM   #11
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
thank you gotta sort my samba problem out then i shall have a read of those sites
 
Old 06-20-2006, 07:09 PM   #12
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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
 
Old 06-20-2006, 09:10 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,347

Rep: Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365
rsync is your friend ....
 
Old 06-21-2006, 01:49 AM   #14
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
or "wget" if the remote machine has an FTP access.
 
Old 06-21-2006, 06:40 AM   #15
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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/*.*
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl/CGI Creating Auto Logouts (like bank sites) anthonysaulnier Programming 3 10-17-2005 12:36 PM
Creating Linked Lists from items in a file SeniorSE Programming 5 09-14-2005 10:53 PM
how do I search for multiple filetypes? fisayo Linux - General 4 07-19-2005 07:05 AM
Apache filetypes and downloads gcobb Fedora 1 02-12-2005 07:55 PM
GNOME filetypes sanmadjack Linux - Software 1 07-11-2004 02:58 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration