![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| how to get a file name & record count of csv file | sirik | UNIX for Dummies Questions & Answers | 2 | 03-06-2008 02:55 PM |
| How count number of fields in a record | sureshg_sampat | Shell Programming and Scripting | 5 | 01-07-2008 06:30 AM |
| record count | dr46014 | Shell Programming and Scripting | 4 | 12-11-2007 04:39 PM |
| splitting a record and adding a record to a file | rsolap | Shell Programming and Scripting | 1 | 08-13-2007 01:58 PM |
| How to count the record count in an EBCDIC file. | oracle8 | UNIX for Dummies Questions & Answers | 1 | 07-26-2006 07:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
What I am trying to do is check if the database query returned any records.
If no records returned then output a message else output results to a file. Right now if I take out the if and else statements the code runs fine and sends the email. If no records returned the email sends the column names. I would like to send a message instead of the column heading. Here is my code can anyone help? #!/bin/ksh #cd /home/john/ . sybase . ss_pto.id echo "****** Please do not reply to this message ******" > ss_pto.status echo " " >> ss_pto.status echo New PTO and Special Requests ADDED as of: `date` >> ss_pto.status echo " " >> ss_pto.status echo Please add to Outlook calendars: >> ss_pto.status #export today=`date` date '+%m %d %Y %H %M %S' | { read MONTH DAY YEAR HOUR MINUTE SECOND DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case "$MONTH" in 0) MONTH=12 YEAR=`expr "$YEAR" - 1` ;; esac DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1` esac } tempdate="$YEAR"-"$MONTH"-"$DAY"" ""$HOUR":"$MINUTE":"$SECOND" isql -U $U -P $P -S $S -w1000 -o tmp_isql.status << label1 use ptodb_rch01_prod go select RTRIM(usr.fname) "First name", convert(char(20), usr.lname) "Last name", convert(char(15), ind.pto_date, 107) "PTO Date", ind.comments "Comments" from ss_pto_user usr, ss_pto_index ind where ind.user_id = usr.user_id and ind.request_date >= '$tempdate' and (ind.class_id = 7 and ind.section_id = 5 or ind.class_id = 2 and ind.section_id = 4 ) order by usr.lname asc go label1 reccnt=`wc -l tmp_isql.status` if [reccnt = 0] message="no records returned" echo $message>>ss_pto.status else cat tmp_isql.status>>ss_pto.status mailx -s"SS PTO" -senders email reciepents email < ss_pto.status |
|
||||
|
The reason is sql returns like this if there are no matching records.
column1 column2 column3 ... ------------------------------------------------------ (0 rows affected) The reccnt=`wc -l tmp_isql.status` always returns more than 0. May be you can try this. recount='cat tmp_isql.status |awk 'NR >3' |grep -v - | grep -v return' if [$recount != "(0 rows affected)"] message="no records returned" echo $message>>ss_pto.status else cat tmp_isql.status>>ss_pto.status mailx -s"SS PTO" -senders email reciepents email < ss_pto.status Here change ' NR>3' according to the number of lines for columns headings Hope this piece of code is useful to you. |
|
||||
|
Quote:
recount='cat tmp_isql.status |awk 'NR >1' |grep -v - | grep -v return' echo $recount>temprecount recount2=`cat temprecount` if ["$recount2" = "(0 rows affected)"] message="no records returned" echo $message>>ss_pto.status else cat tmp_isql.status>>ss_pto.status |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|