The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 08:34 AM
search for the contents in many file and print that file using shell script cdfd123 Shell Programming and Scripting 3 10-07-2007 10:17 PM
Creating file contents using contents of another file ReV Shell Programming and Scripting 21 02-24-2006 10:25 AM
Reading specific contents from a file and appending it to another file dnicky Shell Programming and Scripting 5 10-04-2005 05:45 AM
ls contents of a file douknownam Shell Programming and Scripting 7 06-14-2004 09:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-01-2002
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Unhappy 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 (permalink)  
Old 10-01-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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 (permalink)  
Old 10-02-2002
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
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 (permalink)  
Old 10-02-2002
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
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 (permalink)  
Old 10-02-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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 (permalink)  
Old 10-02-2002
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
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 (permalink)  
Old 10-03-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0