File contents required for emailing.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File contents required for emailing.
# 1  
Old 10-01-2002
Data File contents required for emailing.

I have created three SQL scripts that are run by one central script. What I need to do is verify the output file from the three SQL scripts(KSH Scripts) is worth emailing. This I would like to do by verifiying the contents of the result file.

The contrlooing script creates the result file then the SQL scripts append to it from then on until the opreation completes.

For instance I have ecohed a line for each instance of the SQL script being run into the result file. So there are three lines minimum in the result file, what I would like to do is count the lines if ther are more that three line email the file, if ther are less just delete the file.

I am having trouble assinging a varialbe to the lines counted in the result file.

I have tried;

wc -l result_file
let line_c=$a-$b
if [ lin_c -le 3 ]; then
Email file
else
delete file
fi

HELP!!!!!
# 2  
Old 10-01-2002
I don't know what $a and $b should be, but I think I see what you want to do...
You want to email the file out if it's less than or equal to 3 lines long, and delete it otherwise... right?

for ksh, something like this should work:
Code:
#! /bin/ksh

fil_len=$(wc -l < result_file)
(( fil_len <= 3 )) && {
   mail_the_file_here
   } || {
   otherwise_delete_it
   }

# 3  
Old 10-02-2002
Excellent, it worked.

I had to adjust the final code a little, but the result is exactly what I was trying to do.

Thank you very much.
# 4  
Old 10-02-2002
The result was not correct I have had to adjust the code to get the correct response but am unable to.

fil_len=`wc -l < input_file`
if [ fil_len > 3 ]; then
email file
elif [ file_len < 3 ]; then
delete empty file
fi

The test statement will not accept the value from fil_len, I have output to the screen to see if it is valid and it gives a number but not sure if it is char or numeric.
The output looks like this;
9

No matter what I do it will only select the first part of the statement as true. Regardless of the lines in the file.
All in a Korn Shell (KSH)

sorry for the premature elation!!!! (hair trigger trouble you know)
# 5  
Old 10-02-2002
If it's in braces "[", and not double-perens "((", you'll need to use the "$" character:
Code:
...
if [ $fil_len > 3 ]; then
...

Does that help?
# 6  
Old 10-02-2002
The only thing I had not tried was the

if ((fil_len > 3)) then

I had Tried

if [ $fil_len > 3 ]; then

if [ "$fil_len" > 3 ]; then

if [ "$fil_len" > "3" ]; then

if [ "fil_len" > 3 ]; then

just about every permutation you could thing of......... except

if ((fil_len > 3)) then

Which works successfully (tested fully I might add)

Thanks again for the insight how to resolve this one.
# 7  
Old 10-03-2002
To do numeric tests in either a bracket or double bracket form of if statement, you must use -gt like this...

if [ $fil_len -gt 3 ] ; then

When you use > in that style of if statement you are testing which string comes first in straight ascii sort.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

Help required the cut the whole contents from one file and paste it into new file

Hi, First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong ! I am very new to UNIX scripting. Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :- Code :- (Feb 7, 571 7:07:29 AM),... (4 Replies)
Discussion started by: acidburn_007
4 Replies

4. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

5. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

6. Shell Programming and Scripting

Emailing html file as body not attachment

Hi All, I want to send the html file as message body not as an attachment. below is my code.it is printing the html code as it is in the email. your help is needed urgently. VTIER=$ROOTHOME/vtierlist2.txt genhtml=/$ROOTHOME/genhtml.html MAILTO=/$ROOTHOME/maillist SUBJECT="Vtier Usage... (6 Replies)
Discussion started by: amitbisht9
6 Replies

7. Shell Programming and Scripting

Export SQL results to .TXT file for emailing

Hi everyone, I am new to unix and bash and in need of some help. I am writing a script that will execute a SQL query. The script runs and the SQl query runs, but I cannot figure out how to save the results as a file that can be emailed to a user. Here is my scripts thus far: #!/bin/sh SID=$1... (2 Replies)
Discussion started by: alpinescott
2 Replies

8. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

9. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

10. Shell Programming and Scripting

Creating file contents using contents of another file

Hi, I am not sure how to start doing this so I hope to get some advice as to how to start. I have 2 files. The source file contains data that I needed is in columns delimited by ";". For example, in this format: "CONTINENT","COUNTRY","CITY","ID" "asia","japan","tokyo","123"... (21 Replies)
Discussion started by: ReV
21 Replies
Login or Register to Ask a Question