Sponsored Content
Top Forums Shell Programming and Scripting How to use a string in the for loop? Post 302928876 by srkmish on Tuesday 16th of December 2014 03:59:28 AM
Old 12-16-2014
How to use a string in the for loop?

Hi Guys,

I have the below 2 exception which I want to monitor and subsequently many more. My problem is since the For loop takes the syntax for variable in word1 word2 as separate entities and my error strings are consisting of many words , how to treat the whole error string as a single entity.

Code:
 
Exception 1: org.com.Exception JMS MQ Error
Exception 2: org.db.Exception Db2 SQL Error

What can I do to modify the below code so that I can include individual exceptions in a for loop? The below code will treat each word as a different variable

Code:
for exception in org.com.Exception JMS MQ Error org.db.Exception Db2 SQL Error

---------- Post updated at 01:55 AM ---------- Previous update was at 01:43 AM ----------

Ok. I got it .. It shud be in the following format.

Code:
for exception in "org.com.Exception JMS MQ Error" "org.db.Exception Db2 SQL Error"

---------- Post updated at 03:59 AM ---------- Previous update was at 01:55 AM ----------

Now I am facing another issue where the Awk script is not recognizing the variable passed in for loop i.e. in the below script, it is probably searching for $error string instead of the value of error variable.

How to make awk script recognize the value of the error variable?

Code:
 
rm /tmp/jvm1error.txt
echo "Error" >/tmp/jvm1error.txt
for error in "org.com.Exception JMS MQ Error" "org.db.Exception Db2 SQL Error"
do
a=$(awk -vDT=$(date +"%y%m%d%H%M" -d"- 3 hour") '
                     {sub(/^\[/,"")
                      split ($1, D, "/")
                      split ($2, T, ":")
                      AT=sprintf ("%02d%02d%02d%02d%02d", D[3], D[1], D[2], T[1], T[2])}
             AT > DT && /$error/
        ' /logs/websphere/*jvm1*/SystemOut.log)
 
echo "$a" >> /tmp/jvm1error.txt
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

if statement in for loop of a string

I am attempting to pass a string into awk and loop through it, and then for every occurrance of a certain character perform an action. In this case, for example, echo 1 for each time character r is found in the string. Except I can't get it to work. Could someone please tell me why? echo... (7 Replies)
Discussion started by: Sniper Pixie
7 Replies

2. Shell Programming and Scripting

Help with if loop (string comparison)

Hi Can someone please tell me what is wrong with this (ksh).. if + ]] then echo ${COMP_TEMP} fi What i need here is, say if the variable is a 1 or 2 digit number, then execute the if loop. Basically the variable can either be 1-30 or some other character sequence say '?', '&&'... (4 Replies)
Discussion started by: psynaps3
4 Replies

3. Shell Programming and Scripting

Sed appending string using for loop?

Hi All, I have been trying to format a file using sed. I can't seem to get the syntax right. I want to append the string from file1.txt to file1.csv with the final output file being file2.csv, but before the string is appended to the end of each line, first insert a comma. Here is the sed... (2 Replies)
Discussion started by: cstovall
2 Replies

4. Shell Programming and Scripting

How to loop through every char in a string

for example this string: gLZMQp8i Loop become easy if we add space between each char, How to do it? or other solutions are welcome. (9 Replies)
Discussion started by: honglus
9 Replies

5. Shell Programming and Scripting

find a string in a loop

Hi, Can anyone help with the problem below? I need to read all text files (file1, file2, file3) in a loop and find file1.txt: file2.txt: File3.txt: (7 Replies)
Discussion started by: Lenora2009
7 Replies

6. Shell Programming and Scripting

String concatenation not working in a loop

Hi, First post, so I hope someone can help me with this weirdness :) I have a number files with some rows of information I want to extract, at the same time I want to add to a string some details from the file. I have found two different ways of looping over rows in a file, but one method... (5 Replies)
Discussion started by: LostInTheWoods
5 Replies

7. Shell Programming and Scripting

for loop ( string having spaces )

Dear All, i facing problem to use string having spaces in for loop.. file used for FOR LOOP command.txt rpm -t -v ttm -D -r RJLL -h YELP rpm -t -v ttm -D -r RJLL -h ERRT rpm -t -v ttm -D -r RJLL -h TYYE rpm -t -v ttm -D -r RJLL -h POOL CODE using for execute above command... (3 Replies)
Discussion started by: arvindng
3 Replies

8. Shell Programming and Scripting

Searching for a string using loop.

Hi i am very new to shell scripting. I have got stuck on a portion on my script. Problem : I have 30 logfiles inside /home/test directory. I need to find the string "@ended today" in all the 30 logfiles and print the name of the files which did not have this string. i need to this by... (3 Replies)
Discussion started by: Soma Das
3 Replies

9. UNIX for Dummies Questions & Answers

Loop with Perl (string search)

I am using a perl script to reverse and complement sequences if a string is found. The script works as expected as standalone but I would like to use it in my bash file. However, I am not getting my expected result. My test.txt file >Sample_72... (8 Replies)
Discussion started by: Xterra
8 Replies

10. Shell Programming and Scripting

How to call a string by string from a file to use in for loop?

Hi, I have a below sql query. select * from table where name in ('${name}); I have a requirement to automate this as here i need to pass the string value name from txt file. The text file contains the differnet special characters and i have some 200 names in the text file as follows. 3"... (3 Replies)
Discussion started by: Samah
3 Replies
PDOEXCEPTION(3) 							 1							   PDOEXCEPTION(3)

The PDOException class

INTRODUCTION
Represents an error raised by PDO. You should not throw a PDOException from your own code. See Exceptions for more information about Exceptions in PHP. CLASS SYNOPSIS
PDOException PDOExceptionextends RuntimeException Properties o public array$errorInfo o protected string$code Inherited properties o protected string$message o protected int$code o protected string$file o protected int$line Inherited methods o finalpublic string Exception::getMessage (void ) o finalpublic Exception Exception::getPrevious (void ) o finalpublic mixed Exception::getCode (void ) o finalpublic string Exception::getFile (void ) o finalpublic int Exception::getLine (void ) o finalpublic array Exception::getTrace (void ) o finalpublic string Exception::getTraceAsString (void ) o public string Exception::__toString (void ) o finalprivate void Exception::__clone (void ) PROPERTIES
o $errorInfo - Corresponds to PDO.errorInfo(3) or PDOStatement.errorInfo(3) o $code - SQLSTATE error code. Use Exception.getCode(3) to access it. PHP Documentation Group PDOEXCEPTION(3)
All times are GMT -4. The time now is 07:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy