scanning for '0' value in .txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scanning for '0' value in .txt file
# 1  
Old 10-08-2004
scanning for '0' value in .txt file

Hello

I am a novice shell scripting programmer, so please bare with me.

I have embedded a simple SQL statement into a shell script, which simply returns an integer (its a count (*) statement).

The result of the statement is then oputput to .txt file. So, the number could be 0, 1,2, 10, 50, 101 etc.

What I want to do is send an email if the number output into the .txt file is greater than 0. How do I check that the number output is 0, I thought about checking whether the file contained a 0, but I thought this may not work as it may also return a true value if the number was '10' or '100' etc.

Thanks
# 2  
Old 10-08-2004
You could try something like this, though admittedly, I am not sure if VALUE will actually contain the result you are looking for. In your sql file, you will need to turn headings off (assuming you are using Oracle) and set server output on:

Code:
VALUE=$(sqlplus -s user/password@test_id <<EOF
@my_sql_statement
EOF)

if [ $VALUE -gt 0 ]
 then
   email me
fi

If this didnt work for you, then you could try spooling the value of your sql statement and then parse the spool file for your result. You could do this using an number of tools such as grep, awk, cut, etc. The idea is the same, search for the pattern and evaluate if it is greater than 0.

Last edited by google; 10-08-2004 at 08:27 AM..
# 3  
Old 10-08-2004
if tmp.txt is the file of yr sql o/p;

then ....

i=`cat x`
echo "i=$i"
if test $i -gt 0
then
echo "O/P is greater than 0" > y
sendmail emailname@x.com < y
fi
# 4  
Old 10-08-2004
Assuming Oracle is your database. The following code will do the trick. Just tested it in my environment. Note, sqlplus -s will put sqlplus into silent mode, running without this option will cause the database version and other Oracle information to be displayed when logging into the database. For this code to work, you will want to suppress those messages. You can call an external SQL file instead of embedding the sql as I have done below. The syntax for this is shown in my first post. You can also add a path to the file if you so choose. Happy coding....

Code:
#!/bin/ksh
    
VALUE=$( sqlplus -s userid/passwd <<EOF
 set heading off;
 set serveroutput on;
 select count(*) from my_table;
 quit
EOF)
    
if [ $VALUE -gt 0 ]
then
  echo "Value was Greater than 0. Value=[ $VALUE ]"
  add_email_code_here
else
  echo "Value was Less than 0. Value=[ $VALUE ]"
fi

# 5  
Old 10-11-2004
Thanks guys

Google, I am actually using a syabse databse in this case. I shall give the code a go, but I am not very famiar with either Oracle or Sybase, so don't really know the ins and outs.

Thanks for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scanning a pdf file in Linux shell

I want to search a keyword in a list of pdf files and when i find a match i want to write the title and author of that pdf file to another file. How will I do this using linux shell script? (7 Replies)
Discussion started by: SK33
7 Replies

2. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

3. Shell Programming and Scripting

Reg scanning time based log file

Hi, I have a requirement to scan Oracle's alert log file. This file logs all event for Oracle database and each line will have timestamp followed by messages (which might be one or more lines). Example. Thu Aug 15 17:35:59 2013 VKTM detected a time drift. Please check trace file for more... (1 Reply)
Discussion started by: manickaraja
1 Replies

4. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

5. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

6. UNIX for Dummies Questions & Answers

scanning the file for a particular column

I have a file containing 4 columns. need to scan that file, if all the rows in the column4 have a value ZERO, it should print "everything is fine". And if all are not ZERO , at the first encounter of non ZERO value of 4th column it should print "some problem " may be a silly question, but at... (11 Replies)
Discussion started by: gotam
11 Replies

7. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

8. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies

9. UNIX for Advanced & Expert Users

Scanning file backwards

Is there any way to look for a directory path that is listed any number of lines *before* a keyword in an error message? I have a script that is trying to process different files that are always down a certain portion of a path, and if there is an error, then says there is an error, contact... (2 Replies)
Discussion started by: tekster757
2 Replies

10. Shell Programming and Scripting

How to zip a modified file 15 days before but not scanning my sub directory files

I am using zip -m option to zip my files, but i dont want my sub directories files to be zipped (1 Reply)
Discussion started by: skrish70
1 Replies
Login or Register to Ask a Question