Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Using the Foreach loop, Needing help Post 302564789 by grahamn95 on Friday 14th of October 2011 03:35:16 PM
Old 10-14-2011
Using the Foreach loop, Needing help

I am trying to make a script for my Counter-Strike: Source servers. What i am wanting it to do is for it to restart each server, the only way i can think of doing this in through for each.

Years what i have at the moment.
Code:
server_start() {
	START=`ps x | grep SCREEN | grep $SRV | cut -d '?' -f 1`
		if [ ! -n "$START" ]; then
            echo -e "${txtgrn}${txtbld}$SRV is starting up${txtrst}"
			if [ $SRV = "minecraft" ]; then
				cd $SRV
                                ./$SRV.sh
                                cd
			else
				cd $SRV/css
                                ./$SRV.sh
                                cd
			fi
		else
            echo -e "${txtred}${txtbld}Error: $SRV is already running!${txtrst}"
		fi
}

What this does, the user would enter in this command to start up a server
Code:
./tmf.sh start jailbreak

I am looking for a way to stop / start / update them all at once using one command.

Also i am a bit of noob when it comes to bash so tips and examples would be helpful
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

foreach loop question

Hello, I am new at this forum so please bare with me on this. Within a given directory, I have a list of files in which in each file, I would like to do a substitution. I would like to substitute the string mlcl to mll in each file using the foreach command. I dont quite get how to do that. If... (7 Replies)
Discussion started by: clipski
7 Replies

2. Shell Programming and Scripting

Foreach loop

What am I doing wrong with this foreach loop? foreach var ($argv) @sum = $sum + $var (4 Replies)
Discussion started by: haze21
4 Replies

3. Shell Programming and Scripting

foreach loop

Hi Guys, I have a loop which uses a wildcard i.e. foreach f (*) but when I execute the tcsh file in unix then it gives me an error ->>>>>>>foreach: words not parenthesized<<<<<<<<<<- Any help. (1 Reply)
Discussion started by: abch624
1 Replies

4. Shell Programming and Scripting

foreach loop + 2 variables

In a foreach loop, is it possible for the loop to go through 2 arguments instead of one i.e. instead of foreach i (do stuff for i), we have foreach i j(do stuff for i; do stuff for j) I am working under BASH and TCSH shell environments cheers (3 Replies)
Discussion started by: JamesGoh
3 Replies

5. Shell Programming and Scripting

foreach loop

Hi everyone Does anyone know what is wrong with this script. i keep getting errors foreach filename (`cat testing1`) set string=$filename set depth=`echo "$string" echo $depth end the error is the following testing: line 1: syntax error near unexpected token `(' testing: line 1:... (3 Replies)
Discussion started by: ROOZ
3 Replies

6. UNIX for Advanced & Expert Users

Problem with foreach loop

Hi All, Is there any problem with the below 'foreach' loop? foreach risk_factor ($(cat "$rf_list")) where "rf_list=$SCRIPT/Utility/rflist.txt " I'm wondering, it is throwing below error message: syntax error at line 34: `(' unexpected Any idea/suggestions ? Thanks in advance /... (7 Replies)
Discussion started by: ganapati
7 Replies

7. Shell Programming and Scripting

Using sed with a foreach loop

So I am back again beating my head against the wall with a shell script and getting a headache! I want to change each year in a file (1980, 1981, 1982, 1983, etc.) to the same year followed by a tab. The input is "blah blah (1980) blah blah". I want to get "blah blah (1980 ) blah blah".... (2 Replies)
Discussion started by: Peggy White
2 Replies

8. Shell Programming and Scripting

foreach loop problem

Dear all, I wrote a script to download files and move files in directories according to their name. Now here is the problem: Both p101 and p360 data download successfully, but when I move them according to the year and month, only p101 data can be placed at the right location, p360,... (1 Reply)
Discussion started by: handsonzhao
1 Replies

9. UNIX for Dummies Questions & Answers

foreach loop in csh

Hi everyone I'm new to unix and encountered a small problem i couldnt find out a reason why it doesn't work..please help.. in my csh script when i tried to use the foreach loop like this: foreach x ( ls ) echo $x end when i tried to run it, it printed out 'ls' to the std out instead of... (3 Replies)
Discussion started by: ymc1g11
3 Replies

10. Shell Programming and Scripting

Foreach loop with two variables

I need to put together a script that will take the contents of two different files (database name and database owner) and put them in two variables within a line: foreach x (`cat /local/hd3/dba/tools/build_db_scripts/dbs`) foreach z (`cat /local/hd3/dba/tools/build_db_scripts/dbas`)... (6 Replies)
Discussion started by: deneuve01
6 Replies
ASKMARA(1)							      askmara								ASKMARA(1)

NAME
askmara - do simple dns queries DESCRIPTION
askmara queries the user-specified dns server for records, and outputs the reply in a csv2-compatible format (csv2 is the format of zone files that maradns uses). USAGE
askmara [-n] [-v|-t timeout] query [server] OPTIONS
-t If this is present, the following argument is the askmara timeout, in seconds. Note that askmara can not both have a user-defined timeout and verbose output. -v If this is set, askmara will verbosely output the complete reply that the server sent. Note that this verbose output is not csv2-compatible. -n If this is set, askmara, when sending out a query, will not request DNS recursion; in other words, askmara will request that the remote DNS server not contact other DNS servers to answer the query in question. query dns record to be queried. The query has two sections: The type of record we desire, and the hostname we want this record for. The type of query can have two forms: A one-letter mnemonic, or a numeric rtype followed by a colon. This is immediately concatenated by the full name of the host name we wish to look up. For example, to ask for the IP of 'example.com.', we can use the one-letter mnemonic, in the form 'Aexample.com.', or we can use the numeric RR followed by a colon, giving the query '1:example.com.' (since A has the record type of one). Note that the query name needs the trailing dot at the end. Askmara supports a handful one-letter mnemonics, as follows: A signifies a request for an A (ipv4 address) RR N signifies a NS RR C signifies that we are asking for a CNAME RR S signifies that we want a SOA RR P signifies that we want a PTR RR @ signifies that we mant a MX RR T signifies that we want a TXT RR Z signifies that we want to ask for all RRs. server IP address of the dns server to be queried. If no server is given, askmara will query 127.0.0.1. EXAMPLES
Asking the server with the ip 127.0.0.1 for the IP address of example.com: askmara Aexample.com. Asking the server with the ip 198.41.0.4 for the IP address of example.com: askmara Aexample.com. 198.41.0.4 Asking the server with the ip address 127.0.0.1 for the IP address of example.com, using the rr_number:query format: askmara 1:example.com. Asking the server with the ip address 127.0.0.1 for a SRV record. In particular, we ask for the "http over tcp" service for example.net. Since askmara doesn't have a mnemonic for SRV record types, we use the numeric code (33 for SRV): askmara 33:_http._tcp.example.net. Asking the server with the ip address 127.0.0.1 for the AAAA (ipv6 ip) record for example.net: askmara 28:example.net. Note that the output will be a raw DNS packet in both the SRV and AAAA examples. BUGS
When askmara is asked for an SOA record, the output of askmara closely resembles the format of a csv2 file, but can not be parsed as a csv2 file without modification. askmara outputs multi-chunk ("character-string") TXT records incorrectly (it only outputs the first chunk). SEE ALSO
maradns(8) http://www.maradns.org LEGAL DISCLAIMER
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. AUTHOR
MaraDNS is written by Sam Trenholme. Jaakko Niemi used 5 minutes to roll this manpage together, which Sam has subsequently revised. January 2002 askmara ASKMARA(1)
All times are GMT -4. The time now is 04:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy