Visit Our UNIX and Linux User Community


Help with Scriptoutput and mailing the log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Scriptoutput and mailing the log
# 8  
Old 09-25-2009
Code:
tail -$(grep -n  $(date +"%d %b") /var/log/scriptlog.log | head -1 |awk -F: '{ print $1 }') /var/log/scriptlog.log

Hmm... I missed some brackets ... earlier ..

One of the way I add things is try one command at a time
1. grep -n $(date +"%d %b") /var/log/scriptlog.log
Do you get the line of date ...
2. grep -n $(date +"%d %b") /var/log/scriptlog.log | head -1 |awk -F: '{ print $1 }'
... Do you get some number .. Line number from log file where your date is ..

3. tail -<number what you got from earlier command >

4. Now combine all together ...

Please try this ..
# 9  
Old 09-25-2009
i tried now following -
in my logfile there are only 3 entry´s:

Code:
Wed Sep 23 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
--------------------------------------------
Thu Sep 24 14:24:02 CEST 2009
Script Name
Script1 was read - Success
Script2 was read - Success
Script3 was read - Success
Script4 was read - Success
Script5 was read - Success
--------------------------------------------
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


1:
output:
Code:
grep -n $(date +" %d %b ") /var/log/scriptlog.log
grep: Sep: No such file or directory

But when i try
Code:
grep -n $(date +"%b") /var/log/sportdaten.log

-> without "%d"

then i get output
Code:
1:Wed Sep 23 21:30:01 CEST 2009
10:Thu Sep 24 14:24:02 CEST 2009
29:Thu Sep 24 21:30:01 CEST 2009

2:
Code:
grep -n $(date +"%b") /var/log/sportdaten.log | head -1 |awk -F: '{ print $1 }'
then my output is "1", but "1" is Wed Sep 23 21:30:01 CEST 2009 and not the last day ... Sep 24 
 
is there something wrong?


Last edited by jackcracker; 09-25-2009 at 09:21 AM.. Reason: forget something
# 10  
Old 09-25-2009
Code:
grep -n "$(date +'%b %d')" /var/log/scriptlog.log

let us fool grep ... Smilie ... try this

Why I added %b = Month because I can expect lot of numbers in the log file ... which might not be date

Paste the output ...
# 11  
Old 09-25-2009
ok, here´s my result:

grep -n $(date +"%b") /var/log/scriptlog.log
gives

1:Wed Sep 23 21:30:01 CEST 2009
10:Thu Sep 24 14:24:02 CEST 2009
19:Thu Sep 24 21:30:01 CEST 2009

and

grep -n $(date +"%b") /var/log/scriptlog.log | head -1 |awk -F: '{ print $1 }'
gives

1
# 12  
Old 09-25-2009
I edited it ... '%b %d' ... please try with that ...
# 13  
Old 09-28-2009
Code:
grep -n $(date +"%b %d") /var/log/scriptlog.log

gives result:
grep: 28: No such file or directory
/var/log/scriptlog.log:1:Wed Sep 23 21:30:01 CEST 2009
/var/log/scriptlog.log:10:Thu Sep 24 14:24:02 CEST 2009
/var/log/scriptlog.log:19:Thu Sep 24 21:30:01 CEST 2009
/var/log/scriptlog.log:28:Fri Sep 25 21:30:01 CEST 2009
/var/log/scriptlog.log:37:Sat Sep 26 21:30:01 CEST 2009
/var/log/scriptlog.log:46:Sun Sep 27 21:30:01 CEST 2009

...

which result did you get?
# 14  
Old 09-28-2009
Why don't you simply use tee to add output to the log file and pipe the stdout to the mail command?

Code:
30 21 * * *  /root/script.sh | /usr/bin/tee -a /var/log/scriptlog.log | /usr/bin/mail -s "daily log" your.email@your-host.com

Every time the cron will run your script, it will append output to the log file (-a option of the tee command) and send a mail with the daily log.

---------- Post updated at 08:53 AM ---------- Previous update was at 08:50 AM ----------

Change path to the tee and mail command according to your OS.

Previous Thread | Next Thread
Test Your Knowledge in Computers #296
Difficulty: Easy
Linux Mint 2.0 was based on Ubuntu 6.10 and used the Ubuntu 6.10 package repositories and using it as a codebase.
True or False?

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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

Featured Tech Videos