How to Create LOG and Validate for this Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Create LOG and Validate for this Script
# 1  
Old 10-05-2011
How to Create LOG and Validate for this Script

Hi all,

This is my Script


Code:
#!/bin/bash
current_date=`date +%d-%m-%Y_%H.%M.%S`
Date=`date +%d%m%Y`
Lfriday=`date +%d%m%Y -d last-friday`
RootPath=/var/domaincount/com

mysql zonefile<<EOFMYSQL
CREATE TABLE com$Date(domain VARCHAR(255),col2 VARCHAR(255),col3 VARCHAR(255),col4 VARCHAR(255),id INT(25) NOT NULL AUTO_INCREMENT, KEY (id));
LOAD DATA INFILE '$RootPath/$today.com' INTO TABLE com$Date FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n';
delete from com$Date limit 35;
delete from com$Date order by id desc limit 2;
select count(distinct(SUBSTRING_INDEX(domain, '.',-1))) from com$Date INTO OUTFILE '$RootPath/$today.count';
select count(distinct(SUBSTRING_INDEX(a.domain, '.',-1))) from com$Date a, com$Lfriday b where a.domain=b.domain INTO OUTFILE '$RootPath/$today.overall';

for normal script i can create log, but in that i used mysql queries, suppose for example one sql query not executed properly means how to intimate this issue to administrator..like that i need to log for each query.

how to create, is it possible??
# 2  
Old 10-05-2011
You mean, you want it to send a mail? or what?
# 3  
Old 10-05-2011
yes mail alert
# 4  
Old 10-05-2011
Something like:
Code:
#!/bin/bash
current_date=`date +%d-%m-%Y_%H.%M.%S`
Date=`date +%d%m%Y`
Lfriday=`date +%d%m%Y -d last-friday`
RootPath=/var/domaincount/com

mysql zonefile<<EOFMYSQL || echo "query failed" | sendmail 'username@where'
CREATE TABLE com$Date(domain VARCHAR(255),col2 VARCHAR(255),col3 VARCHAR(255),col4 VARCHAR(255),id INT(25) NOT NULL AUTO_INCREMENT, KEY (id));
LOAD DATA INFILE '$RootPath/$today.com' INTO TABLE com$Date FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n';
delete from com$Date limit 35;
delete from com$Date order by id desc limit 2;
select count(distinct(SUBSTRING_INDEX(domain, '.',-1))) from com$Date INTO OUTFILE '$RootPath/$today.count';
select count(distinct(SUBSTRING_INDEX(a.domain, '.',-1))) from com$Date a, com$Lfriday b where a.domain=b.domain INTO OUTFILE '$RootPath/$today.overall';
EOFMYSQL

To have sendmail, you have to have an MTA of some sort installed. If you have none and don't want to bother setting up a mail server, ssmtp is a simple stub of a mailserver that only sends, and sends by logging in as a mail client to something else.
# 5  
Old 10-05-2011
LOG=/var/tmp/log/com/comcount$current_date.log


Code:
mysql zonefile<<EOFMYSQL || echo "query failed" >> $LOG
CREATE TABLE com$Today(domain VARCHA(255),col2 VARCHAR(255),col3 VARCHAR(255),col4 VARCHAR(255),id INT(25) NOT NULL AUTO_INCREMENT, KEY (id));
LOAD DATA INFILE '$RootPath/$Today.com' INTO TABLE com$Today FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n';
delete from com$Today limit 35;
delete from com$Today order by id desc limit 2;
select count(distinct(SUBSTRING_INDEX(domain, '.',-1))) from com$Today INTO OUTFILE '$RootPath/$Today.count';
select count(distinct(SUBSTRING_INDEX(a.domain, '.',-1))) from com$Today a, com$Lfriday b where a.domain=b.domain INTO OUTFILE '$RootPath/$Today.overall';

cat $LOG | mail -s " com Tld Count log" 07anis@gmail.com

i give like this but its not writting into the log file..any idea what mistake iam doing??
# 6  
Old 10-05-2011
You forgot the EOFMYSQL I labelled in red, which is causing lines below it to be interpreted as part of the mysql script and not the shell one.

You do have sendmail actually working, right?
# 7  
Old 10-05-2011
Sorry Man..I missed to post here..but using EOFMYSQL statement only i run myscript -- i got error only

ya 100% working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to develop a bash script to create customized report from the server log

Hi, I need to develop a bash script to create customized report from the server log (red hat 5.8 64 bit Operating system). The following is one of the log for our internal application task. <2015.03.03 20:09:52 274 +0800><I><DSCTH01><http-0.0.0.0-443-2><security> GUI request succeeded for... (1 Reply)
Discussion started by: pugazhendhi_r
1 Replies

2. Shell Programming and Scripting

Create, validate and using dynamic variables in Bash scripting

Hi All, I am really struggling to solve this problem, this might be small but I am not able to, can somebody help me? I have few directories and these directories receives text files in large amount with in fraction of seconds. So I just want to send all the files in current directory to... (2 Replies)
Discussion started by: VasuKukkapalli
2 Replies

3. AIX

Script to validate between two environments

Hi, I trust that you are well - I'm a bit new into AIX and I've been assigned a task to write a script that will always validate between our two Prod (Prod A and Prod B) environments to confirm which prod we live at. The two environments are exact replicas and this check I need to put in... (5 Replies)
Discussion started by: Twaggzk
5 Replies

4. Shell Programming and Scripting

Create archive and nil the content of log file using script

Plese help I need a urgent requirement. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log) file to 0 kb and then in the archive folder log files are name to test.tar test1.tar test2.tar EX: /home/abc/ test.log ... (1 Reply)
Discussion started by: johney1981
1 Replies

5. Shell Programming and Scripting

Please help me validate script

Hi Guys, Im a newbie to scripting and have a small assignment. can someone please confirm if the script i have written would work fine as we dont have a test server to test :( Scenario - copy 2 files from an ftp server (windows) to a linux machine (a perticular folder). run 2 different... (0 Replies)
Discussion started by: nishantvshah
0 Replies

6. Shell Programming and Scripting

Script creation(How to validate SID?)

I was going write a script from following site. Unix Shell Script to Execute Oracle SQL Query (link removed) My configuration setting for oracle XE. export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server export PATH=$PATH:$ORACLE_HOME/bin export ORACLE_SID=XE but after... (4 Replies)
Discussion started by: pinga123
4 Replies

7. Homework & Coursework Questions

shell script that can create, monitor the log files and report the issues for matching pattern

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write an automated shell program(s) that can create, monitor the log files and report the issues for matching... (0 Replies)
Discussion started by: itian2010
0 Replies

8. Shell Programming and Scripting

Help to create a script to parse log files

Hello everybody, I need some help here to create a script to parse a log file. Here is a sample of the log file : 0x42258940 (Debug) Cache SUMMARY attrs now/668 min/668 max/668. 0x42258940 (Debug) RSVD SUMMARY reserved space max requested/128 MB accounted now/0 MB 0x42258940 (Debug)... (12 Replies)
Discussion started by: Samb95
12 Replies

9. Shell Programming and Scripting

How to create a log file of a script?

hi, How to create a log file of a script. Like spool does . I want to create a log file of whatever the script is doing step wise. like -xvf does or something better then that. thanks ... (3 Replies)
Discussion started by: madfox
3 Replies

10. Shell Programming and Scripting

permissions to create log file from script

hi all, have a script which i am using to generate a log file. i use "touch out.log" command to create the file and later on i want to echo lines to this file. for some reason it keeps giving me this error when i try and create the file ; touch: out.log cannot create i have... (3 Replies)
Discussion started by: cesarNZ
3 Replies
Login or Register to Ask a Question