Email backup log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Email backup log
# 1  
Old 05-31-2013
Email backup log

Hi,
I have a server which appends to two different backup logs, a summary and a full log,
I want to write a script which will email out this mornings backup,
the problem is that in the log files the date is in the below format:

Code:
Fri May 31,2013 02:30

the summary log file I can just use Head to get the data, but in the full log because the log is a different length each day is proving difficult,
In the full summary each days log is delimited by

Code:
****************************************************************

I was trying to grep the full summary for the date and then using AWK print 500 lines below it, which works just not in the script,

Code:
#!/bin/ksh
DATE= `date | awk '{print $3, $2, $4}' | sed 's/\(.*\) /\1,/'`
cat /cfmtools/backups/logs/full | awk 'c-->0;/$DATE/{c=500; print}'

If i run it is get:

Code:
-bash-3.00$ ./backup_mail_V2
./backup_mail_V2: line 2: May: command not found

Can anyone help?
# 2  
Old 05-31-2013
Quote:
Originally Posted by Bdoydie
the problem is that in the log files the date is in the below format:
Code:
Fri May 31,2013 02:30

See he man page of the "date" command, it shouldn't be so complicated to get the date in this format to compare it to the log contents.

Quote:
Originally Posted by Bdoydie
In the full summary each days log is delimited by

Code:
****************************************************************

Then it is easy: use "sed"s range capability to print/delete only the lines in certain range:

Code:
mydate="$(date +'<appropriate format string here>')"

sed -n '/'"$mydate"'/,/^\*\{25\}/ p' /path/to/logfile

The sed-invocation will only print the lines starting with the first line containing your date to a line starting with 25 asterisks (i haven't bothered to count your line, correct the number if necessary). If you want to delete the files from the log use the same method but use "d" instead of "p" as a command.

I hope this helps.

bakunin
# 3  
Old 05-31-2013
I have made some progress,
i changed the DATE variable to
Code:
DATE=  "`date | awk '{print $3, $2, $4}' | sed 's/\(.*\) /\1,/'`"

And now the only issue is it thinks the output
Code:
May 31,2013

is a command rather than text,

I want the variable to be text as im passing it into the next awk command as a string
# 4  
Old 05-31-2013
You are doing this overly complicated. Again, read the man page of "date" and play around with the format strings you can supply to "date".

The reason why it thinks it is a command is:

Code:
variable=value      # correct
variable= value     # wrong
variable =value     # wrong too

There must not be any blanks between "=" and the value or the variables name.

I hope this helps.

bakunin
# 5  
Old 05-31-2013
Code:
DATE=$(date +%b" "%d","%Y)

I do suggest you do not use back tics `` but $()

If you need it in awk, do it like this, no need to add date to wariable, when awk read it directly, eks
Code:
awk '{print $1,d}' d="$(date +%b" "%d","%Y)" infile


Edit
This should print the first 500 line from today date:
Code:
awk 't {print;--t} !f && $0~d {f=1;t=500}' d="$(date +%b" "%d","%Y) /cfmtools/backups/logs/full


Last edited by Jotne; 05-31-2013 at 08:48 AM..
# 6  
Old 05-31-2013
Ok here is a stupid question but i can never remember how to do it,
the script is working fine but for some reason it is duplicating some of the lines

How do you remove duplicate lines?

---------- Post updated at 03:53 PM ---------- Previous update was at 12:58 PM ----------

This is really strange,
I tried running the script and I dont get any response,
just goes back to the prompt,
This made me think there are no entries in the log file for today,
but if i run the date command by its self it displays the date the way it should

Code:
-bash-3.00$ date +%b" "%d","%Y
May 31,2013

and if i then run:
Code:
cat /cfmtools/backups/logs/full | awk 'c-->0;/May 31,2013/{c=500; print}'

It again works fine but not in the script
# 7  
Old 05-31-2013
Give some example from the full log file.

Why do you swap line around and using cat, when I show you how to do it correct?

Wrong!
Code:
cat /cfmtools/backups/logs/full | awk 'c-->0;/May 31,2013/{c=500; print}'

Correct Smilie
Code:
awk 'c-->0;/May 31,2013/{c=500; print}' /cfmtools/backups/logs/full

Did you test this?
Code:
awk 't {print;--t} !f && $0~d {f=1;t=500}' d="$(date +%b" "%d","%Y) /cfmtools/backups/logs/full

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

2. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

3. Shell Programming and Scripting

Need a Script - Parse the log backup

Hello all, I need a script to parse the backup logs. I am newbie to scripting, please help. (7 Replies)
Discussion started by: sandeep007
7 Replies

4. Shell Programming and Scripting

How to take the backup of log basing on size

Hi All, I have a small doubt, there is one process which is writing the log file. That log file is getting overwritten every 5 hours. As i donot want to lose the data, i want to write a script which will check the max. file size defined for the file and take the backup of the file before... (1 Reply)
Discussion started by: saiki
1 Replies

5. Shell Programming and Scripting

Email script when automatic backup is finsihed

Hello all, i'm still new to this site and thought i might find some help here :). lately i performed a script to make an automatic backup of some files in certain directories. the script looks something like this: #! /bin/bash ##############VARIABLES path=/export/home/cassi/Backup... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

6. UNIX for Dummies Questions & Answers

Showing a daily backup job from a unique log file.

Hi guys, I´m a newbie in Linux, but I´m trying to solve some problems studying on my own, but I´ve had some problems with AWK. Look, I have one single backup log file per server and I want to make a daily delection from the last backup job to show in a intranet of my work. The log files are from... (0 Replies)
Discussion started by: metalfreakbr
0 Replies

7. Shell Programming and Scripting

parsing email log

Can anyone give me some examples of how I can parse the following lines of text so that all characters up to and including the @ symbol are deleted? Also, any duplicates would need to be deleted in order to produce the desired output. Any help is much appreciated and explanations of any... (5 Replies)
Discussion started by: jjamd64
5 Replies

8. UNIX for Dummies Questions & Answers

where are my email log files

I am trying to find the email log file that would have info on users downloading their pop mail. Our email is hosted on a unix server running apache. I am not sure the exact version of mail software running, but when I telnet to the mail server the response I get is this "+OK POP3 v2003.83rh... (3 Replies)
Discussion started by: mstarcom
3 Replies

9. Windows & DOS: Issues & Discussions

Backup Directories and SubDirectories with log using DOS

Hello. I need to Backup an Directorie with Sub-directories and after that put in a log file. Then i need to copy several files and have a log file to. All that using old DOS. Could someone help ? Thanks in advance (1 Reply)
Discussion started by: osramos
1 Replies

10. Solaris

creating log files for a backup script on solaris

I have a simple backup script that I am running to back up drives across the network. However I need to have detailed log files for this script such as time backup started, what was backed up, if there were any errors and the time that the backup was complete. I would also like the script to... (3 Replies)
Discussion started by: valicon
3 Replies
Login or Register to Ask a Question