UNIX Script required for count the records in table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX Script required for count the records in table
# 1  
Old 05-08-2014
UNIX Script required for count the records in table

Hi Friends,

I looking for the script for the count of the records in table.

and then it's containg the zero records then should get abort.

and should notify us through mail.

Can you please help me out in this area i am lacking.
# 2  
Old 05-08-2014
I am assuming a database table.

We need the following information to give you a useful answer:

1. What database - Oracle, Sql server, etc.?

2. What shell do you use - bash, ksh, etc.?
# 3  
Old 05-08-2014
Is this a homework assignment?
# 4  
Old 05-08-2014
I have written below script plz check it and correct it if any.

Code:
#!/bin/sh
count=`sqlplus $username/$password@$tnsname << EOF
select count(*) from table;
exit;
EOF`
if [ $count = 0 ]
then 
exit 1
fi
mailx -s " record count " abc@xyz.com < $count
exit 0


Last edited by Don Cragun; 05-08-2014 at 04:51 PM.. Reason: Add CODE tags.
# 5  
Old 05-08-2014
Quote:
Originally Posted by victory
I have written below script plz check it and correct it if any.

Code:
#!/bin/sh
count=`sqlplus $username/$password@$tnsname << EOF
select count(*) from table;
exit;
EOF`
if [ $count = 0 ]
then 
exit 1
fi
mailx -s " record count " abc@xyz.com < $count
exit 0

We are not here to write and debug your programming projects. If you make an honest effort and need help, we'll be happy to help you.

What error message(s) did your script produce when you ran it?

Can sqlplus fail (leaving count unset)? If it can, the if test will probably yield a syntax error. (Don't you think you should quote the expansion of $count?

How does file redirection work? If sqlplus says you have 27 records in your table, do you have a file named 27? If so, do you want the mail message to contain the contents of the file named 27, or do you want the message to be 27? If mailx reads the message from standard input, how would you change:
Code:
mailx -s " record count " abc@xyz.com < $count

to send a message containing the text 27 instead of sending the contents of a file named 27?
These 2 Users Gave Thanks to Don Cragun For This Post:
# 6  
Old 05-09-2014
What output do you get if you don't try to capture the output from sqlplus into the variable. My guess is that there are all sorts of headers and general information being written out.

What do you get (paste it in CODE tags please), and how will you handle it or trim it down?

Have a look at the options for calling sqlplus to see if that helps. You can get this by running sqlplus -?




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python Script to take file count and insert into DB2 table

Team I have files in different directories . How can i take the count of latest file and insert into Db2 table . I am using awk 'END{print NR+1-ARGC}' (File name) to get the counts. How can i take 1.The count of latest file 2.Insert into Db2 table( File Name and Counts) . cd... (4 Replies)
Discussion started by: Perlbaby
4 Replies

2. Shell Programming and Scripting

Help Needed: UNIX shell variables to store Oracle table records

Hello Folks, I'm working on a requirement to automate the process of generating report(csv file) using metadata info stored in an Oracle table and E-mail it to respective people. Meta data table: Report_ID,Report_SUB_ID,Report_DB,Report_SQL,Report_to_email_Id 1,1,DEV,'select * From... (2 Replies)
Discussion started by: venkat_reddy
2 Replies

3. Shell Programming and Scripting

Intelligent Script to Insert Records in Database Table

Hello All Members, I am new to this forum and to the shell scripting. I want to write a shell script to do the following: Scenario: I have a pipe delimited .txt file with multiple fields in it. The very first row of the file contains the name of the column which resembles the name of the... (18 Replies)
Discussion started by: chetanojha
18 Replies

4. Shell Programming and Scripting

Script to count the dataflow in a table in oracle database

I need to write a unix shell script to connect to oracle database and retrieve data from a table, the script should count the total number of rows till date in that table number of rows which are getting filled per hour on current day and the peak hour of the current day number of rows which are... (5 Replies)
Discussion started by: PhAnT0M
5 Replies

5. Shell Programming and Scripting

Script to count particular type of records

Hi, I have a huge file containing thousands of records which are of following pattern: TYPE1 { originNodeType : "IVR" originHostName : "AAIVR" originTransactionID : "01310559" originTimeStamp : "20110620192440+0530" hostName : "hhhh" voucher : '0'D rProfileID : "ZZZZ" Before {... (5 Replies)
Discussion started by: madhukar1anand
5 Replies

6. Shell Programming and Scripting

count and compare no of records in bash shell script.

consider this as a csv file. H,0002,0002,20100218,17.25,P,barani D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 T,5 N i want to read the csv file and count the number of rows that start with D and... (11 Replies)
Discussion started by: barani75
11 Replies

7. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

8. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

9. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question