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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that will show output starting from 24-hours earlier to present
# 1  
Old 12-19-2011
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
Code:
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 Regards,
rymnd_12345
# 2  
Old 12-19-2011
Code:
for x in `ls`; do [[ `stat -c%y $x | awk '{print $1}'` == `date -d "yesterday" +%F` ]] && echo $x; done


-------------------------------
The above code will only print those whose date is yesterday. Try the below:
Code:
for x in `ls`; do [ `stat -c%y $x | cut -c1-16 | sed 's/[- :]//g'` -ge `date -d"yesterday" +%Y%m%d%H%M` ] && echo $x; done


Last edited by balajesuri; 12-19-2011 at 08:16 AM..
# 3  
Old 12-19-2011
# 4  
Old 12-19-2011
What does "get the logs" mean? Please give and example. Please mention what Operating System and version you have and what Shell you use.
# 5  
Old 12-19-2011
Hi methyl,

"get the logs" means that isn't it that after executing the command
Code:
cat /var/log/messages > output-file

I want to get only logs starting from yesterday (24hrs earlier) up to the current system time the script has been executed.

example if today is Dec 19 15:00:00 and then I executed the script, it will give an output of the logs starting from Dec 18 15:00:00 up to Dec 19 15:00:00.

Please advice,
rymnd_12345
# 6  
Old 12-19-2011
@rymnd_12345: Did you try solution posted in post #2?
# 7  
Old 12-19-2011
Hi balajesuri,

I have just read the 2nd script that you posted, now it works. Thanks so much! Thanks ULF Smilie


Br,
rymnd_12345
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get output of fields starting from 2nd line

Hi All, I am using the following command in Linux: sar -r 30 3 Linux 2.6.18-194.3.1.7.3.el5xen 02/07/2013 02:55:47 PM kbmemfree kbmemused %memused kbbuffers kbcached kbswpfree kbswpused %swpused kbswpcad 02:56:17 PM 128646024 22348920 14.80 230232 15575860 75497464 ... (4 Replies)
Discussion started by: a1_win
4 Replies

2. UNIX for Dummies Questions & Answers

find the no of processes that ran 2 hours before or earlier

Is there a way to find out the total no of processes that were running ? - 2 or 3 hours before - list those no of processes (3 Replies)
Discussion started by: jansat
3 Replies

3. Shell Programming and Scripting

Bash script show Kill system output

Hi we are calling kill -9 $pid command from bash script it gives below output, but we need to hide the output. i tried /dev/null but ni luck. is there any alternate way to schive this. ../kill_scr.sh: line 42: 1891 Killed /tmp/anr_rest_mul_wc.sh Soalris 10. ... (2 Replies)
Discussion started by: sachinbutala
2 Replies

4. Shell Programming and Scripting

Show pages on a script's big output

Hi again: I have this code which gives an large output(several screens), and I want to display on screen at a time (like more does)....how can I do this? echo echo "Los roles en el sistema son:" echo lsrole -a dfltmsg ALL|sed 's/dfltmsg=/Descripcion=/' thanks Israel. (4 Replies)
Discussion started by: iga3725
4 Replies

5. Shell Programming and Scripting

Two files one file is dependent and it does not show an output

xxxxx (2 Replies)
Discussion started by: vinayrao
2 Replies

6. UNIX for Advanced & Expert Users

prtdiag -v show no output

Dear All....Help required prtdiag -v command shows no output on my V440 server. Following is the details: root@sdp16b>prtdiag -v root@sdp16b> root@sdp16b>uname -a SunOS sdp16b 5.9 Generic_122300-31 sun4u sparc SUNW,Sun-Fire-V440 root@sdp16b>echo $path /usr/sbin /usr/bin /usr/sbin... (6 Replies)
Discussion started by: Junaid
6 Replies

7. Shell Programming and Scripting

Help required to parse Oracle imp show=y output to DDL Commands

Hi, I generated an Oracle schema DDL script file using the show=y option of the Oracle import utility but the file that it generates needs a little more formating before we can run this as simple DDL comands to generate the schema at Target using the script file.Here is the simplified output of... (1 Reply)
Discussion started by: rajan_san
1 Replies

8. Shell Programming and Scripting

echo doesnot show output

hi every one , i m new in unix . i m trying shell scripting . set v = abc echo $v but it does not show any output . please help me (4 Replies)
Discussion started by: samy123
4 Replies

9. Shell Programming and Scripting

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. (4 Replies)
Discussion started by: *Jess*
4 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