LinuxQuestions.org
Register a domain and help support LQ
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 11-17-2010, 03:38 PM   #1
omle
LQ Newbie
 
Registered: Nov 2010
Posts: 2

Rep: Reputation: 0
Talking reading info from one file in to another


hi there firstly great site has helped answer nearly all the problems ive ran into so far and i am a total linux newbie

been playing around making a server to play some games on running centos 5.5

what ive spent a while looking for (a few days) is a way to make a file which i will call startup this will contain some values

Code:
mod_directory="etpub"
port="27960"
log_name="console.log"
vm="0"
dedicated="2"
ip="ipaddress"
logfile="3"
sv_pure="1"
server_sv_punkbuster="1"
config1="game.cfg"
i want this so i can easily edit just this file and save it as ive installed webmin and i can edit this file with that

but i have a file that i want that data to be read in to

Code:
this is what starts up my game so far
nohup ./etded +set vm_game 0 +set sv_pure 1 +setdedicated 2 +net_ip ipadress 
+set fs_game etpub +net_port 27960 +set sv_punkbuster 0 +exec game.cfg > echo console.log < /dev/null &

but i wanted something more like this


nohup ./server_exec +set server_vm +set +set sv_pure sv_pure +set dedicated 2 +net_port port +net_ip server_ip 
+set fs_game echo mod_directory +set sv_punkbuster server_sv_punkbuster +exec config1 > echo server_log_name  < /dev/null &
so the variables in the one file are read by the file i can then call to start the game up

if some 1 could point me in the correct direction id be ive had a good look around and typed loads of searches in to websites and google etc but tbh i dont know what i would actually call this hence why im stuck

thanks for your time!

Last edited by omle; 11-17-2010 at 03:39 PM.
 
Old 11-17-2010, 03:55 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Let's say in your data file, you have:
Code:
mod_directory="etpub"
port="27960"
Now, in your startup script you're wanting to write, you could read the data file into variables, like:
Code:
MODDIR=$(awk -F= '/^mod_directory/{gsub("\"","",$2); print $2}' data_file)

# above, we've grabbed field #2 from the line containing mod_directory="etpub"
# in the input file (data_file), removed the quotes from it, and returned
# the resulting string/value into the shell variable $MODDIR.

# Later down your script, after you have read in all your variables
# by repeating the above stuff for each data entry, you execute your startup command
# and stick your variables in where they belong:

nohup ./server_exec +set "$MODDIR" +set $OTHER_VARIABLE +set $VARIABLES blah blah blah....
If you do not wish to remove the quotation marks from the fields that awk prints, just eliminate the red piece in the code.

You could do this another way too, by using a "while read/do done" loop, which would read your data file in line by line, split the line into name/value pairs, and loop through a case/esac loop checking what each line contains, and setting your variables accordingly. The results are the same in the end - it's a matter of what method you are comfortable with.

Good luck!
 
  


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
Gnome/Nautilus issues Beagle-Tracker, file transfer info, replace file info, popup. Mysticle31 Linux - Software 0 01-08-2008 06:30 PM
reading struct elf_prstatus for process info in linux? sanjaykhuntia Linux - Enterprise 0 10-26-2007 04:56 AM
Reading JPEG Header info lucky6969b Programming 4 06-05-2006 06:12 AM
Convert an info file(bash.info.gz) to a single html file Darwish Linux - Software 2 09-24-2005 07:51 AM
2.6.x kernel reading HDD info incorrectly - missing partitions bulliver Linux - Hardware 1 09-01-2004 07:23 AM


All times are GMT -5. The time now is 12:10 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