|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
BASH ZCAT EGREP Shell Script
I created a backup script that emails all the admins when the backup is complete and attaches a log file of what what backed up. On occasion, something happens in which the backups stop working, I started "grep"ing around /var/log/syslog and I usually find the smoking gun. My goal is to zcat /var/log/syslog* and egrep all the instances of an occurence on a date that an error occurred. So I began testing using: Grabs Date Code:
err_date=$((date)|gawk -F ' ' 'BEGIN {IGNORECASE=1;} {print $2,$3}')
echo $err_date
Oct 23Now I want to simply use zcat and egrep the lines that contain that date. Code:
zcat /var/log/syslog* |egrep '^`echo $err_date`' gzip: /var/log/syslog: not in gzip format gzip: /var/log/syslog.1: not in gzip format I remove the backticks Code:
zcat /var/log/syslog* |egrep '^$err_date`' gzip: /var/log/syslog: not in gzip format gzip: /var/log/syslog.1: not in gzip format Code:
zcat /var/log/syslog*|gawk 'BEGIN {IGNORECASE=1;} /^$err_date/'I tried many combinations but cant seem to catch my error in usage. I want egrep to use "Oct 23" from variable "$err_date". ?? Last edited by metallica1973; 10-23-2012 at 01:04 PM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Use Code:
grep "^$err_date" instead of Code:
egrep '^$err_date`' . |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Are you performing operations on .gz files..? I normally prefer. ![]() Code:
zcat *.gz | .... |
|
#4
|
|||
|
|||
|
Thanks for the reply but it didnt work: Code:
zcat /var/log/syslog* |grep "^$err_date" gzip: /var/log/syslog: not in gzip format gzip: /var/log/syslog.1: not in gzip format ? ---------- Post updated at 01:07 PM ---------- Previous update was at 01:05 PM ---------- Thanks PAMU, I would like to grep all files under: /var/log/syslog* which would include: Code:
-rw-r----- 1 syslog adm 133256 Oct 17 08:04 /var/log/syslog.7.gz -rw-r----- 1 syslog adm 146465 Oct 18 07:56 /var/log/syslog.6.gz -rw-r----- 1 syslog adm 158721 Oct 19 07:48 /var/log/syslog.5.gz -rw-r----- 1 syslog adm 172300 Oct 20 07:40 /var/log/syslog.4.gz -rw-r----- 1 syslog adm 183107 Oct 21 07:49 /var/log/syslog.3.gz -rw-r----- 1 syslog adm 206954 Oct 22 07:45 /var/log/syslog.2.gz -rw-r----- 1 syslog adm 5840020 Oct 23 07:49 /var/log/syslog.1 -rw-r----- 1 syslog adm 1342525 Oct 23 13:06 /var/log/syslog thanks |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
try using Code:
zcat /var/log/syslog.*.gz | grep "^$err_date" |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
If I just: Code:
zcat -v /var/log/syslog* Oct 17 08:04:31 Dartanion nullmailer[1572]: Starting delivery: protocol: smtp host: mail. file: 1350367203.17107 Oct 17 08:04:31 Dartanion nullmailer[9414]: smtp: Failed: Connect failed Oct 17 08:04:31 Dartanion nullmailer[1572]: Sending failed: Host not found Oct 17 08:04:31 Dartanion nullmailer[1572]: Starting delivery: protocol: smtp host: mail. file: 1350108002.10660 Oct 17 08:04:31 Dartanion nullmailer[9415]: smtp: Failed: Connect failed Oct 17 08:04:31 Dartanion nullmailer[1572]: Sending failed: Host not found Oct 17 08:04:31 Dartanion nullmailer[1572]: Starting delivery: protocol: smtp host: mail. file: 1350453603.30086 Oct 17 08:04:31 Dartanion nullmailer[9416]: smtp: Failed: Connect failed Oct 17 08:04:31 Dartanion nullmailer[1572]: Sending failed: Host not found Oct 17 08:04:31 Dartanion nullmailer[1572]: Starting delivery: protocol: smtp host: mail. file: 1350215920.13026 Oct 17 08:04:31 Dartanion nullmailer[9417]: smtp: Failed: Connect failed Oct 17 08:04:31 Dartanion nullmailer[1572]: Sending failed: Host not found Oct 17 08:04:31 Dartanion nullmailer[1572]: Delivery complete, 8 message(s) remain. 95.8% I can see it going through all the files and or most of the files but I cannot seem to pass my variable into grep or egrep. ? Last edited by Franklin52; 10-24-2012 at 02:41 AM.. Reason: fixed code tags |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Code:
for i in /var/log/syslog*
do
echo "$i" | grep "gz$" > /dev/null 2>&1 && zcat "$i" | grep "^$err_date"
echo "$i" | grep "gz$" > /dev/null 2>&1 || grep "^$err_date" "$i"
done |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| zcat two files | jacobs.smith | Shell Programming and Scripting | 11 | 10-04-2012 12:28 PM |
| bash: need to have egrep to return a text string if the search pattern has NOT been found | bash4ever | Shell Programming and Scripting | 6 | 07-12-2012 02:54 AM |
| zcat on Linux | felixmat1 | Linux | 2 | 06-19-2008 03:42 PM |
| zcat --> Arg list too long | muneebr | UNIX for Dummies Questions & Answers | 3 | 08-19-2004 04:40 AM |
| bash shell script | norsk hedensk | Shell Programming and Scripting | 4 | 08-02-2003 07:27 PM |
|
|