Trouble with variable and command assignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble with variable and command assignment
# 1  
Old 10-16-2014
Trouble with variable and command assignment

I have a section of a script where I want to check a log file for a certain oracle error and if there is only one error (and it is ORA-39152) then I want to email that script is complete. Otherwise email failure and log.

Somehow with this while the log only has one error and it is ORA-39152, I keep getting the failure message. Can someone look over and maybe see my foolish mistake?
Code:
counterrors=$(egrep 'ORA-' ${MLOG5} | wc -l)

if [egrep 'ORA-39152:' ${MLOG5}] && [$counterrors = 1];
then
   uuencode $MLOG $MLOG1 $MLOG2 $MLOG3 $MLOG4 $MLOG5 | mail -s "PLR ARCHIVING SUCCESSFULLY COMPLETED ${datestamp}" xxxxxxxx
   exit
else
   ((ERRORS=ERRORS+1))
   mail -s "PLR ARCHIVING ERRORS IN PRICEARCH IMPORT LOG " xxxxxx < $MLOG5
   exit $ERRORS
fi


Last edited by cougartrace; 10-16-2014 at 04:16 PM..
# 2  
Old 10-16-2014
What kind of error? Why are you essentially egreping twice. One to set the counterrs var and the other in the first part of the if statement?
This User Gave Thanks to blackrageous For This Post:
# 3  
Old 10-16-2014
You don't put egrep in [ ] like that, and there must always be spaces between the [ ] and their contents. Also, use -eq for arithmetic comparision.

Code:
if egrep 'ORA-39152:' "${MLOG5}" >/dev/null && [ "$counterrors" -eq 1 ]

But you could do this all with one awk:

Code:
COUNT=$(awk '/ORA-/ { N++ } /ORA-39152:/ { E=1 } END { print N+0 ; exit !E }' "${MLOG5}")
ORA="$?"

if [ "$ORA" -eq 0 ] && [ "$COUNT" -eq 1 ]
then
...
else
...
fi


Last edited by Corona688; 10-16-2014 at 05:58 PM..
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 10-16-2014
the test alias `[' requires a space in before and after the comparative expression
e.i.
Code:
if [ $counterrors -eq 1 ]

This User Gave Thanks to Aia For This Post:
# 5  
Old 10-16-2014
thank you. Wow one foolish mistake and one big thanks for the awk part which I never thought about
# 6  
Old 10-16-2014
I just had to change the awk statement slightly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies

2. Shell Programming and Scripting

Same Variable Assignment

Hi I have a strange problem: In my shell script I am performing a copy task: . prop.txt cp -r $dir/ $dir/archive $dir is fetched from a property file (prop.txt) which stores its value dir=/opt/data Now the problem is another dir1 comes into picture. I only want to add... (1 Reply)
Discussion started by: ankur328
1 Replies

3. Shell Programming and Scripting

Trouble with variable assignment and reading in shell scripting

Hi, I have an inputfile with some table names in it. For ex: t_arnge t_profl t_fac I need a script which reads the line one by one and need to assign to some dynamic variable. If to explain the above example: i need some a=table_name1 table_name1=t_arnge in first time and... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

4. Solaris

Looking to understand what this command $$ does in variable assignment?

Hi Folks, I'm looking to figure something out in an existing script I'm trying to understand. the command in question(on a Solaris Box using KSH) is: WORKDIR=/tmp/namereplaced.exec.$$.$RANDOM Now, I know it's setting the $workdir environmental variable... And I understand most of... (2 Replies)
Discussion started by: Marc G
2 Replies

5. Shell Programming and Scripting

Trouble with passing Variable from bash to awk gsub command

Would really appreciate it if someone could point out my mistake in this line of code, i've been staring blankly at it trying everything i can think of some time now and coming up with nothing. #!/bin/bash echo "Enter Username" read Username awk -F: -v var=${Username} '/^var:/... (9 Replies)
Discussion started by: Nostyx
9 Replies

6. Shell Programming and Scripting

Help with variable assignment

Hi, In AIX I have a variable with , (coma) separated values assigned to it like shown below var1=apple,boy,chris i want to convert this to var1='apple','boy','chris' the number of values assigned to var1 might change and it could be from 1 to n any suggestions please? (3 Replies)
Discussion started by: rahul9909
3 Replies

7. Shell Programming and Scripting

assignment to variable from eval command

Hi Gurus, I am having 2 parameters as below parm1=value1 parm2=parm1 I want to evaluate parm1 value using eval echo \$$parm2 and later i want to assign this value to other variable which i will be using in if statement like : if ]; then do this....... fi could you please suggest... (5 Replies)
Discussion started by: k_vikash
5 Replies

8. Shell Programming and Scripting

command output to variable assignment and screen simultaneously

Hello Folks, I have a script that runs a command (rsync) that sometimes takes a long time to complete and produces diagnostic output on stdout as it runs. I am currently capturing this output in a variable and using it further in the script. I would like to continue to capture this output... (2 Replies)
Discussion started by: mbm
2 Replies

9. Shell Programming and Scripting

variable assignment in new shell

Hi, I'm writing a KSH script, and at one point, I have to call a new shell and perform some variable assignments. I noticed that the assignment is not working. Please see two samples below: Command 1: #>ksh "i=2;echo I is $i" Output: #>I is Command 2: #>ksh <<EOF > i=2 > echo I... (7 Replies)
Discussion started by: maverick80
7 Replies

10. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies
Login or Register to Ask a Question