Sponsored Content
Top Forums Shell Programming and Scripting Help with Scriptoutput and mailing the log Post 302356270 by jackcracker on Friday 25th of September 2009 04:10:37 AM
Old 09-25-2009
Help with Scriptoutput and mailing the log

Hi Guys,

i´ve oncemore a little question, hope somebody can help me.

Here´s my "problem":
I´ve running a script via cron every evening at 21:30 - this script
reads 5 xml-Files and output the result in a logfile.
When the script ends without errors i´ve an entry in my logfile and also when the script ends with an error.

Here´s this script:
Code:
#! /bin/sh
#
cd /srv/www/htdocs/import
/bin/echo "--------------------------------------------"
/bin/date
echo Script "Name"
 
ausgabe="$(/usr/bin/php5 script1.php 2>&1)";
status=$?;
#echo "$ausgabe";
echo -n 'Script1 was read - ';
[[ $status -eq 0 ]] && [[ -z "$ausgabe" ]] && echo -n Success || echo -n Error - ;
echo " $ausgabe";
 
ausgabe="$(/usr/bin/php5 script2.php 2>&1)";
status=$?;
#echo "$ausgabe";
echo -n 'Script2 was read - ';
[[ $status -eq 0 ]] && [[ -z "$ausgabe" ]] && echo -n Success || echo -n Error - ;
echo " $ausgabe";
 
ausgabe="$(/usr/bin/php5 script3.php 2>&1)";
status=$?;
#echo "$ausgabe";
echo -n 'Script3 was read - ';
[[ $status -eq 0 ]] && [[ -z "$ausgabe" ]] && echo -n Success || echo -n Error - ;
echo " $ausgabe";
 
ausgabe="$(/usr/bin/php5 script4.php 2>&1)";
status=$?;
#echo "$ausgabe";
echo -n 'Script4 was read - ';
[[ $status -eq 0 ]] && [[ -z "$ausgabe" ]] && echo -n Success || echo -n Error - ;
echo " $ausgabe";
 
ausgabe="$(/usr/bin/php5 script5.php 2>&1)";
status=$?;
#echo "$ausgabe";
echo -n 'Script5 was read - ';
[[ $status -eq 0 ]] && [[ -z "$ausgabe" ]] && echo -n Success || echo -n Error - ;
echo " $ausgabe";

and here´s the Logfile:

when everything is okay:
Code:
Thu Sep 24 21:30:01 CEST 2009
Script Name
Script1 was read - Success
Script2 was read - Success
Script3 was read - Success
Script4 was read - Success
Script5 was read - Success

and when something went wrong:
Code:
Tue Sep 22 21:30:01 CEST 2009
Script Name
Script1 was read - Error - You have an error in your SQL syntax; check the manual that corresponds to your MyS
QL server version ... bla bla ....2009', kng = 'T', segnr1 = 'G', segname =
 '' at line 1
Script2 was read - Success
Script3 was read - Success
Script4 was read - Success
Script5 was read - Success

and here´s my crontab:
Code:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXiQy98H installed on Thu Sep 24 14:56:51 2009)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
30 21 * * *  /root/script.sh >> /var/log/scriptlog.log

Now i want that respectively the entry from the last day in this logfile will be sent via mail to root.
Perhaps something like this:
cat the logfile, grep the last entry, put it in a temp-file, send this file via mail and delete it then ...

but i´ve no idea how to do this ...

Parhaps, can somebody help me?
Thanks in advance ...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mailing an attachment

Hi, I'm fairly new to using Unix and I was just wondering can someone please tell me the simplest way to mail and attachement using the mail command using Solaris? I have tried using uuencode file name | mail johndoe@ttp.ie but it hasn't worked. I have been mailing the file to myself using... (4 Replies)
Discussion started by: gerwhelan
4 Replies

2. Shell Programming and Scripting

Mailing an attachment

Hi, I need to compress (zip) a flat file and mail the same as an attachment. I had tried the following piece of code. But when i open the attachment in mail, the data is incorrect (displays all junk characters). tar cf abc.tar abc.txt compress abc.tar uuencode abc.tar.Z abc1.wri | mailx -s... (0 Replies)
Discussion started by: gayath3
0 Replies

3. UNIX for Dummies Questions & Answers

Mailing an attachment

Hi, I need to compress (zip) a flat file and mail the same as an attachment. I had tried the following piece of code. But when i open the attachment in mail, the data is incorrect (displays all junk characters). tar cf abc.tar abc.txt compress abc.tar uuencode abc.tar.Z abc1.wri | mailx... (4 Replies)
Discussion started by: gayath3
4 Replies

4. Shell Programming and Scripting

Mailing Problem

I have a Unix server with SunOS 5.8 installed on it. I have set a cron job which will send mail across the two different networks. As of now i can only send mails to the abc.com who owns the server but would also like to send it to xyz.com is there any setting or parameter wherein i need to add... (2 Replies)
Discussion started by: nimish
2 Replies

5. Shell Programming and Scripting

Mailing script

Hi, I have a file lets say FILE1. FILE1 ------ name,age charlie,25 harry,29 david,32 Pls help me writing a mailing script.... which will mail the content of file in the body of the mail & it will look something like below in two columns. name age charlie 25 harry 29... (1 Reply)
Discussion started by: 46019
1 Replies

6. Shell Programming and Scripting

HTML mailing

Hi All, I have a comma separated file as below. file-1 ---------- a,b,c d,e,f g,h,i . . . I want to send the above file in Mail in HTML format with all the values of each column in separate cells i.e. the body of the mail should be in tabular format & each field should be separate... (2 Replies)
Discussion started by: 46019
2 Replies

7. Shell Programming and Scripting

Mailing Script

Hi, I am totally New to This Scripting Area.We have developed some reports in Bo and User need those reports to be sent through Unix Server (SFTP). Can any one provide me script for transfering File from one location to other with the requirement like if that file fails to reach destination... (4 Replies)
Discussion started by: Sashanth_S
4 Replies

8. UNIX for Dummies Questions & Answers

Regarding mailing of logs

Hi Folks , I have one query I traverse to a location where logs are being made daily, Now I want that a particular log in that logs directory to be get mailed to me automatically at a particular time on daily basis at my mail id, Please advise the command for that.. for ex the directory is... (7 Replies)
Discussion started by: SankalpS
7 Replies

9. UNIX for Advanced & Expert Users

Regarding mailing of logs

Hi Folks, I have an application which logs get continuously refreshed and made after every 1 second , I want that those logs get mailed to me at my email id sara@somewhere.com The location is cd /var/log/abc/log Please advise the command so that I can mail abc.log at my mailid inbox... (2 Replies)
Discussion started by: SankalpS
2 Replies

10. Shell Programming and Scripting

Mailing the job log

Hi All, i am a begginner in autosys. i want the job log to be mailed if a job gets failed in autosys.please help me with this (0 Replies)
Discussion started by: sahe
0 Replies
All times are GMT -4. The time now is 02:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy