Scripts to output contents every 3 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripts to output contents every 3 hours
# 1  
Old 08-01-2006
Scripts to output contents every 3 hours

Hi all,
I would like to capture the file contents every 3 hours. I will put the schedule inside crontab, how to get only incremental contents from the last 3 hours?
Thanks.
# 2  
Old 08-01-2006
One way is to actually truncate the file after you take the output. That way, you don't have to worry about the older contents at all. Or you could write a script to check the number of lines in the file when you actually take the output and then keep taking the output from that point on.
# 3  
Old 08-01-2006
Below shows my script:
Code:
C_DATE=`date +"%a %b %e "`
C_HOUR=`date +"%H"`
C_TIME=`date +"%p"`
ORACLE_HOME='/u01/oradw';export ORACLE_HOME
ORACLE_SID=PDWH;export ORACLE_SID

sed -n "/^$C_DATE/,$ p" $ORACLE_HOME/admin/pdwh/bdump/alert_$ORACLE_SID.log > temp$$
#
sed -n '/^ORA-/ p' temp$$ > ora_errors

Every 3 hours, the script will check and grab the content to an output file. What I get is everything on a specific date. I would wan to have an incremental output that generate only during that 3 hours. Thanks

Last edited by blowtorch; 08-01-2006 at 10:59 PM.. Reason: to put in code tags
# 4  
Old 08-01-2006
Try something like this:
Code:
#!/usr/bin/ksh

C_DATE=`date +"%a %b %e "`
C_HOUR=`date +"%H"`
C_TIME=`date +"%p"`

read line 0<test.line

sed -n -e"$line,$ p" test >> test$$
wc -l test|tr -d '[:space:][:alpha:]' > test.line

Here, you always read ahead from the last line in the file. So you do not have to look for the date either. You can initialize this to start from the first line in the file by entering "1" in the test.line file or start from the current state by entering the current 'number of lines' in the test.line file.

Please test this before putting in a production env.
# 5  
Old 08-02-2006
Hi, Thx a lot for the script. We will rename that file to another name once a week, which means the original file will start with 0 bytes 0 lines again.

So it's not accurate to count with lines.
How to print contents that consist of 2 strings, eg: ora & date?
Bcoz my script is to print out contents consists of ora- only.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Looping through the contents of array for output name

Hi all, I am trying to loop through the string contents of an array, to add it during the saving of the output files. I am trying this code to print each column and save it to unique file name, but it doesn't work. Thanks for any help. fnam=(japan usa uk) alldata.dat contained sample data... (1 Reply)
Discussion started by: ida1215
1 Replies

2. Shell Programming and Scripting

Using scripts to create output files

been messing around with linux for a few months...not too good yet. thinking about taking a class or something, this #### is hard.......anyway, im trying to make an output file using the input from a prompt. heres basically what i have now (random example) echo -n "Please enter your name: " read... (7 Replies)
Discussion started by: rickbobb4444
7 Replies

3. Shell Programming and Scripting

Command need to be used for the scripts output differences

Hi All, Actually we want to know the command need to use if the difference between two files are null, then it should not send as mail. Oterwise it should send as mail alert. Below for your reference, # Email the spoolfile. diff free_sp_new.log free_sp_old.log if output of above... (1 Reply)
Discussion started by: thanvir.akram
1 Replies

4. Shell Programming and Scripting

Script that will show output starting from 24-hours earlier to present

Hi Guys, Good day! I hope you could help me on this, I have a file that conatins output upon executing cat /var/log/messages, then what I want is to get the logs that has been generated only starting from 24-hours earlier at the time of actual execution of the script. Is this possible? Best... (9 Replies)
Discussion started by: rymnd_12345
9 Replies

5. Shell Programming and Scripting

Help with ksh script to display output with specific contents

This is Input - starts with Storage Group Name and ends with Shareable and the loop continues all I need is Storage group name and Alu numbers in the below output format requested. Storage Group Name: abcd Storage Group UID: 00:00:000:00:0:0:0 HBA/SP Pairs: HBA UID ... (6 Replies)
Discussion started by: maddysa
6 Replies

6. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

7. Shell Programming and Scripting

Deleting the contents of a folder older than X hours

Every day a new .zip file is uploaded to a folder and at mid-night the zip file is to be extracted into a /data/ folder, inside a date-named folder. # This should extract the contents of a zip file into the /data/ folder into a date based folder /usr/bin/unzip -a -o... (15 Replies)
Discussion started by: worchyld
15 Replies

8. UNIX for Dummies Questions & Answers

output redirection in scripts

I am trying to write a script that will remove any line in 2 given text files starting with '-'. the output should be to the second file. this is what I tried: #!/bin/csh -f cat $1 $2 | grep -v '^-' > $2 the problem is the after executing the script, file2 contains only the lines from... (7 Replies)
Discussion started by: stewie griffin
7 Replies

9. UNIX for Dummies Questions & Answers

What is the output of that Shell Scripts Plz tell me

tr "" "" | sort | awk 'length($0)>0' | uniq -c (1 Reply)
Discussion started by: brain_full
1 Replies

10. Shell Programming and Scripting

To alter perl /bin/date output by - 5 hours

Hello! I'm using a perl script which calls the time and date from a remote server using the line /bin/date - What is needed in this line to reduce the output time 5 hours? Thanks (2 Replies)
Discussion started by: Texan
2 Replies
Login or Register to Ask a Question