Sponsored Content
Top Forums Shell Programming and Scripting script for get lines with specific time. Post 302586907 by ooilinlove on Tuesday 3rd of January 2012 03:18:34 PM
Old 01-03-2012
I tried it because I am still a novice unix.
I think it is.

Code:
time.log
.
.
00:0[0-9]
00:1[0-9]
00:2[0-9]
00:3[0-9]
00:4[0-9]
00:5[0-9]
.
.

my script
Code:
DATE=`date "+%Y%m%d"`
LOGPATH="/home/nagios/"
LOGNAME="Status.log"
LOG=$LOGPATH$LOGNAME
LOGMON="/home/nagios/logmon.log"
echo "$LOG"
date="02-01-2012 "

dates=DATE
times=TIME
attemp=ATTEMP
success=SUCCESS
fail=FAIL

for li in `cat time.log`
do

a1=`cat Status.log  |grep "$date$li" |wc -l`
a2=`cat Status.log  |grep "$date$li" |grep "Status=0" |wc -l`
a3=`cat Status.log  |grep "$date$li" |grep -v "Status=0" |wc -l`

echo "$date     $times  $a1     $a2     $a3" >> logmon.log
done

while true
        do
                clear
                echo " Monitor  Success "
                echo "Server name = `uname -n`"
                echo " -------------------------------------------------------------------------------------------------------------------------"
                echo "$dates    $times  $attemp $success        $fail" |awk '{printf "%15s %15s %15s %15s %15s\n", $1,$2,$3,$4,$5}'
                tail -30 $LOGMON |awk '{printf "%15s %15s %15s %15s %15s\n", $1,$2,$3,$4,$5}'
                sleep 100 
        done

my script output.
Code:
 Monitor  Success 
Server name = Abidamaru
 -------------------------------------------------------------------------------------------------------------------------
           DATE            TIME          ATTEMP         SUCCESS            FAIL
     02-01-2012            TIME              48              46               2
     02-01-2012            TIME              91              88               3
     02-01-2012            TIME              55              53               2
     02-01-2012            TIME              25              25               0
     02-01-2012            TIME              38              36               2
     02-01-2012            TIME              67              66               1
     02-01-2012            TIME              48              46               2

I have a problem, it displays real time.
And display the date and time. I wanted it to come out in this format.

Code:
DATE                                 TIME   
2012-01-04           00:50:00
2012-01-04           01:00:00
2012-01-04           01:10:00

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to read specific lines in a file

I have a file with contents as follows Record 1: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 5: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 6:... (5 Replies)
Discussion started by: varshanswamy
5 Replies

2. Shell Programming and Scripting

need help--script to filter specific lines from multiple txt files

Hi folks, - I have 800 txt files - those files are cisco router configs router1.txt router2.txt ... router800.txt I want to accomplish the following: - I want to have a seperate file with all the filenames that I want to process - I want a script that goes trough all those... (7 Replies)
Discussion started by: I-1
7 Replies

3. UNIX for Advanced & Expert Users

How to delete specific lines at the same time

Dear All I have a pattern which look like this: 2 20080312_10:55:35.800 Spain-Telefonica ISC 9 IAM 927535957 34670505334 f 275 COT b 700 ACM b 6577 CPG b 10726 ANM b 202195 REL f 202307 RLC :COMMA: NCI=15,FCI=2101,CPC=0A,TMR=00,USI,OFI=00: :COMMB: BCI=0214,OBI=01,ACT: :RELCAUSE:10: This... (1 Reply)
Discussion started by: zanetti321
1 Replies

4. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

5. Shell Programming and Scripting

Ending script at specific time.

Hello Everybody.. I've written the script that kick off through CRON job and kill itself by specific time. I've start time and end time specify in env file. i.e START_TIME=1500 (03:00 PM) END_TIME=0600 (06:00 AM) It always works good if my START_TIME is before midnight and my... (4 Replies)
Discussion started by: nirav_soni
4 Replies

6. UNIX for Dummies Questions & Answers

Script required to truncate all the lines except a specific snippet.

Hi, I have a file with the following structure. XXXXX........... YYYYY........... ................. .................. ZZZZZZ...... qwerty_start.............. .................. ................. .................. querty_end................ .............................. (3 Replies)
Discussion started by: abinash
3 Replies

7. Shell Programming and Scripting

script for get lines with specific date

I'm a newbie in AIX, i want to make a script for grep any lines with date bellow 20 PRINT0089-88615 data1 3072 Mon Dec 19 17:53:49 WITA 2011 PRINT0089-88616 data1 4096 Mon Dec 19 17:53:49 WITA 2011 PRINT0089-88618 data1 5120 Mon Dec 19... (7 Replies)
Discussion started by: michlix
7 Replies

8. Shell Programming and Scripting

Script to run commands at a specific time.

Hello All, I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are 1. rm -rf /path/to/folder 2. mail the content of a file. How do i achieve this. Thanks. ... (4 Replies)
Discussion started by: Siddheshk
4 Replies

9. Shell Programming and Scripting

Removing specific lines from script files.

Hello, Activity to perform: 1. Find all of the "*.tmp" files in a given user directory 2. Determine which ones have "find" in them. 3. Replace the "find sequence" of commands with a "list set" of commands. Example: Original file: -------------- define lastn1 = "A" define... (7 Replies)
Discussion started by: manishdivs
7 Replies

10. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies
TIME(2) 						     Linux Programmer's Manual							   TIME(2)

NAME
time - get time in seconds SYNOPSIS
#include <time.h> time_t time(time_t *t); DESCRIPTION
time returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds. If t is non-NULL, the return value is also stored in the memory pointed to by t. RETURN VALUE
On success, the value of time in seconds since the Epoch is returned. On error, ((time_t)-1) is returned, and errno is set appropriately. ERRORS
EFAULT t points outside your accessible address space. NOTES
POSIX.1 defines seconds since the Epoch as a value to be interpreted as the number of seconds between a specified time and the Epoch, according to a formula for conversion from UTC equivalent to conversion on the naive basis that leap seconds are ignored and all years divisible by 4 are leap years. This value is not the same as the actual number of seconds between the time and the Epoch, because of leap seconds and because clocks are not required to be synchronised to a standard reference. The intention is that the interpretation of sec- onds since the Epoch values be consistent; see POSIX.1 Annex B 2.2.2 for further rationale. CONFORMING TO
SVr4, SVID, POSIX, X/OPEN, BSD 4.3 Under BSD 4.3, this call is obsoleted by gettimeofday(2). POSIX does not specify any error conditions. SEE ALSO
ctime(3), date(1), ftime(3), gettimeofday(2) Linux 2.0.30 1997-09-09 TIME(2)
All times are GMT -4. The time now is 09:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy