How to get the start time of a long-running Linux process? - linux

Is it possible to get the start time of an old running process? It seems that ps will report the date (not the time) if it wasn't started today, and only the year if it wasn't started this year. Is the precision lost forever for old processes?

You can specify a formatter and use lstart, like this command:
ps -eo pid,lstart,cmd
The above command will output all processes, with formatters to get PID, command run, and date+time started.
Example (from Debian/Jessie command line)
$ ps -eo pid,lstart,cmd
PID CMD STARTED
1 Tue Jun 7 01:29:38 2016 /sbin/init
2 Tue Jun 7 01:29:38 2016 [kthreadd]
3 Tue Jun 7 01:29:38 2016 [ksoftirqd/0]
5 Tue Jun 7 01:29:38 2016 [kworker/0:0H]
7 Tue Jun 7 01:29:38 2016 [rcu_sched]
8 Tue Jun 7 01:29:38 2016 [rcu_bh]
9 Tue Jun 7 01:29:38 2016 [migration/0]
10 Tue Jun 7 01:29:38 2016 [kdevtmpfs]
11 Tue Jun 7 01:29:38 2016 [netns]
277 Tue Jun 7 01:29:38 2016 [writeback]
279 Tue Jun 7 01:29:38 2016 [crypto]
...
You can read ps's manpage or check Opengroup's page for the other formatters.

The ps command (at least the procps version used by many Linux distributions) has a number of format fields that relate to the process start time, including lstart which always gives the full date and time the process started:
# ps -p 1 -wo pid,lstart,cmd
PID STARTED CMD
1 Mon Dec 23 00:31:43 2013 /sbin/init
# ps -p 1 -p $$ -wo user,pid,%cpu,%mem,vsz,rss,tty,stat,lstart,cmd
USER PID %CPU %MEM VSZ RSS TT STAT STARTED CMD
root 1 0.0 0.1 2800 1152 ? Ss Mon Dec 23 00:31:44 2013 /sbin/init
root 5151 0.3 0.1 4732 1980 pts/2 S Sat Mar 8 16:50:47 2014 bash
For a discussion of how the information is published in the /proc filesystem, see
https://unix.stackexchange.com/questions/7870/how-to-check-how-long-a-process-has-been-running
(In my experience under Linux, the time stamp on the /proc/ directories seem to be related to a moment when the virtual directory was recently accessed rather than the start time of the processes:
# date; ls -ld /proc/1 /proc/$$
Sat Mar 8 17:14:21 EST 2014
dr-xr-xr-x 7 root root 0 2014-03-08 16:50 /proc/1
dr-xr-xr-x 7 root root 0 2014-03-08 16:51 /proc/5151
Note that in this case I ran a "ps -p 1" command at about 16:50, then spawned a new bash shell, then ran the "ps -p 1 -p $$" command within that shell shortly afterward....)

As a follow-up to Adam Matan's answer, the /proc/<pid> directory's time stamp as such is not necessarily directly useful, but you can use
awk -v RS=')' 'END{print $20}' /proc/12345/stat
to get the start time in clock ticks since system boot.1
This is a slightly tricky unit to use; see also convert jiffies to seconds for details.
awk -v ticks="$(getconf CLK_TCK)" 'NR==1 { now=$1; next }
END { printf "%9.0f\n", now - ($20/ticks) }' /proc/uptime RS=')' /proc/12345/stat
This should give you seconds, which you can pass to strftime() to get a (human-readable, or otherwise) timestamp.
awk -v ticks="$(getconf CLK_TCK)" 'NR==1 { now=$1; next }
END { print strftime("%c", systime() - (now-($20/ticks))) }' /proc/uptime RS=')' /proc/12345/stat
Updated with some fixes from Stephane Chazelas in the comments; thanks as always!
If you only have Mawk, maybe try
awk -v ticks="$(getconf CLK_TCK)" -v epoch="$(date +%s)" '
NR==1 { now=$1; next }
END { printf "%9.0f\n", epoch - (now-($20/ticks)) }' /proc/uptime RS=')' /proc/12345/stat |
xargs -i date -d #{}
1 man proc; search for starttime.

ls -ltrh /proc | grep YOUR-PID-HERE
For example, my Google Chrome's PID is 11583:
ls -l /proc | grep 11583
dr-xr-xr-x 7 adam adam 0 2011-04-20 16:34 11583

$ ps -p 182454 -o lstart=
Mon Oct 18 17:26:44 2021
But can I get the answer in epoch seconds?

ps -eo pid,cmd,lstart | grep YOUR-PID-HERE

ps -eo pid,etime,cmd|sort -n -k2

use the command ls -ld /proc/process_id where process_id can be find using top command

Related

crontab running twice but ps ax shows only one crond process

I am trying to run a crontab which executes a bash script which triggers mail command. I have done only one entry in crontab for my user. Also doing ps ax | grep cron results only one crond process. I don't know why i am getting mails twice
Cron logs
Aug 7 14:38:10 centos crond[29299]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 85% if used.)
Aug 7 14:38:11 centos crond[29299]: (CRON) INFO (running with inotify support)
Aug 7 14:38:11 centos crond[29299]: (CRON) INFO (#reboot jobs will be run at computer's startup.)
Aug 7 14:40:01 centos CROND[29376]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Aug 7 14:50:01 centos CROND[29940]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Aug 7 14:59:01 centos CROND[30388]: (test_user) CMD (bash /home/test_user/dev/mail_test_user.sh)
Aug 7 15:00:01 centos CROND[30585]: (test_user) CMD (bash /home/test_user/dev/mail_test_user.sh)
Aug 7 15:00:01 centos CROND[30586]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Aug 7 15:01:01 centos CROND[30775]: (root) CMD (run-parts /etc/cron.hourly)
Aug 7 15:01:01 centos run-parts(/etc/cron.hourly)[30775]: starting 0anacron
Aug 7 15:01:01 centos run-parts(/etc/cron.hourly)[30787]: finished 0anacron
Aug 7 15:01:01 centos run-parts(/etc/cron.hourly)[30775]: starting 0yum-hourly.cron
Aug 7 15:01:01 centos run-parts(/etc/cron.hourly)[30795]: finished 0yum-hourly.cron
Crontab list
#reboot autossh -M 8000 -f -N -R 9000:localhost:22 remote_user#192.168.0.3
#reboot autossh -M 8002 -f -N -R 9001:localhost:5901 remote_user#192.168.0.3
#reboot autossh -M 8004 -f -N -R 9002:localhost:80 remote_user#192.168.0.3
0,59 * * * * bash /home/vikas/dev/mail_test_user.sh
Contents of mail_test_user.sh
echo "I am up :)))" | mail -s "Notification : test_user#centos.localdomain [STAG]" foobaar22#gmail.com
ps aux | grep cron results
root 29299 0.0 0.0 126300 1692 ? Ss 14:38 0:00 /usr/sbin/crond -n
test_user 31650 0.0 0.0 112640 964 pts/0 S+ 15:13 0:00 grep --color=auto cron
Any luck why the hack this is happening ?
I also tried rebooting and restarting crond but not working.
The second line is result of your grep command. This is process of grep command not your cronjob process. Because it matches your search criteria.
The error is in setting up cronjob it should be */59 instead of 0/59.

Ubuntu 12.04 High CPU usage on Amazon EC2 Small instance

I am running a small instance on Amazon EC2 with Ubuntu 12.04 LTS.
I have also setup Cloudwatch Alarm on the instance.
The problem is that CPU utilization goes above 90% sometimes and I get notification alarm for that.
I have set a cronjob on instance which runs at every minute and stores the top 3 running processes based on highest CPU usage in a log file. Cronjob is as below.
* * * * * ps -eo pcpu,pid,args --no-headers | sort -n -r | head -3 | perl -pe 'print scalar(localtime()), " ";' >> ps_log/log
But I can't see any process with high CPU usage when I run this command on cron log.
cat ps_log/log | sort -k 6 -n -r | head -10
Following is the latest result of cron log.
Tue May 13 17:44:01 2014 17.1 10171 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 18:06:01 2014 15.1 10502 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 13:28:01 2014 14.7 6526 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 09:56:01 2014 12.4 3277 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 18:06:01 2014 11.4 10508 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Wed May 14 02:32:36 2014 11.0 16936 ps -eo pcpu,pid,args --no-headers
Tue May 13 13:32:01 2014 10.3 6619 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 18:06:01 2014 10.2 10501 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 11:08:01 2014 9.6 4802 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Wed May 14 02:58:07 2014 8.5 17268 ps -eo pcpu,pid,args --no-headers
I can show the two Alarm results and the result of cronlog at which the Alarm notification came.
Reason for State Change: Threshold Crossed: 1 datapoint (96.72) was greater than or equal to the threshold (80.0).
Timestamp: Tuesday 13 May, 2014 15:42:09 UTC
Cronlog:
Tue May 13 15:39:20 2014 2.0 8481 perl -pe print scalar(localtime()), " ";
Tue May 13 15:39:20 2014 1.6 8478 ps -eo pcpu,pid,args --no-headers
Tue May 13 15:39:20 2014 1.2 8004 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 15:41:08 2014 1.7 8527 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin --user=nobody --log-error=/opt/lampp/var/mysql/ip-10-178-52-49.err --pid-file=/opt/lampp/var/mysql/ip-10-178-52-49.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306
Tue May 13 15:41:08 2014 1.5 8547 ps -eo pcpu,pid,args --no-headers
Tue May 13 15:41:08 2014 0.9 8003 [httpd] <defunct>
Tue May 13 15:43:01 2014 6.0 8578 sort -n -r
Tue May 13 15:43:15 2014 5.0 8577 ps -eo pcpu,pid,args --no-headers
Tue May 13 15:43:24 2014 3.3 8579 head -3
Tue May 13 15:44:21 2014 1.2 8527 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin --user=nobody --log-error=/opt/lampp/var/mysql/ip-10-178-52-49.err --pid-file=/opt/lampp/var/mysql/ip-10-178-52-49.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306
Reason for State Change: Threshold Crossed: 1 datapoint (96.72) was greater than or equal to the threshold (80.0).
Timestamp: Tuesday 13 May, 2014 15:42:09 UTC
Cronlog:
Tue May 13 15:39:20 2014 2.0 8481 perl -pe print scalar(localtime()), " ";
Tue May 13 15:39:20 2014 1.6 8478 ps -eo pcpu,pid,args --no-headers
Tue May 13 15:39:20 2014 1.2 8004 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 15:41:08 2014 1.7 8527 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin --user=nobody --log-error=/opt/lampp/var/mysql/ip-10-178-52-49.err --pid-file=/opt/lampp/var/mysql/ip-10-178-52-49.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306
Tue May 13 15:41:08 2014 1.5 8547 ps -eo pcpu,pid,args --no-headers
Tue May 13 15:41:08 2014 0.9 8003 [httpd] <defunct>
Tue May 13 15:43:01 2014 6.0 8578 sort -n -r
Tue May 13 15:43:15 2014 5.0 8577 ps -eo pcpu,pid,args --no-headers
Tue May 13 15:43:24 2014 3.3 8579 head -3
Tue May 13 15:44:21 2014 1.2 8527 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin --user=nobody --log-error=/opt/lampp/var/mysql/ip-10-178-52-49.err --pid-file=/opt/lampp/var/mysql/ip-10-178-52-49.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306
Tue May 13 15:44:21 2014 0.7 8569 CRON
Tue May 13 15:44:21 2014 0.7 8501 /opt/lampp/bin/httpd -k start -DSSL -DPHP5 -E /opt/lampp/logs/error_log
Tue May 13 15:44:21 2014 1.2 8527 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin --user=nobody --log-error=/opt/lampp/var/mysql/ip-10-178-52-49.err --pid-file=/opt/lampp/var/mysql/ip-10-178-52-49.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306
Tue May 13 15:44:21 2014 0.7 8569 CRON
Now is there any way I can catch the process with high CPU usage? A website is hosted on the instance which has very low traffic.
Any help would be appreciated.
A couple of things:
You may see a disconnect between reported cpu usage on linux in a
virtual machine and what Amazon reports as the real cpu usage. Note
that the latter is correct. Cpu usage stats monitoring via ps and top are
unreliable, a good explanation resides here:
http://www.axibase.com/cloud/2010/07/22/ec2-monitoring-the-case-of-stolen-cpu/
Regardless of the accuracy of the top and ps commands, something is
causing cpu to spike. Ps and top should at least tell you which processes are using the most. Instead of calling ps once a minute which may
miss the offending process, why not run it in a loop from a bash
script with a short loop time (like every 10 seconds)? Redirect it
to a log file and and you should be able to find a ps or top entry
within a few seconds of the alarm. Something like this:
while :
do
date
echo
ps -eo pcpu,pid,args --no-headers
echo
top -c -b -n 1
echo
sleep 10
done

Automatically launching Firefox from terminal using at command

I am a beginner at linux and really enthusiastic to learn the OS. I am trying to launch Firefox(or any other software like Evince) from the command line as follows:
[root#localhost ~]# at 1637
[root#localhost ~]# at> firefox
[root#localhost ~]# at> ^d
The job gets scheduled without any error. But at the specified time it does not run.
I also tried giving the following path:
[root#localhost ~]# at 1637
[root#localhost ~]# at> /usr/bin/firefox
[root#localhost ~]# at> ^d
Still no result. But When I try to use echo to display a text on the screen it appears at the specified time as desired. What might be the issue?
I think you have not set DISPLAY. at will run in separate shell where display is not set.
try the following code.
dinesh:~$ at 2120
warning: commands will be executed using /bin/sh
at> export DISPLAY=:0
at> /usr/bin/firefox > firefox.log 2>&1
at> <EOT>
job 7 at Tue Mar 11 21:20:00 2014
If it is still failing check firefox.log for more information.
1) Its not always recommended to run things as root
2) You can also try ./firefox if you are in the current directory of firefox. In linux you need to pay attention to your path variable. Unless . (the current directory) is in your path you will have to type ./program if the program is in the same directory as you.
Also you need to pay attention to file permissions: In linux you have read-write-eXecute access.
ls -l will do a list of directories and show the file permissions:
drwxr-xr-x 10 user staff 340 Oct 6 2012 GlassFish_Server/
drwx------# 15 jeffstein staff 510 Oct 6 15:01 Google Drive/
drwxr-xr-x 20 jeffstein staff 680 May 14 2013 Kindle/
drwx------+ 67 jeffstein staff 2278 Jan 26 14:22 Library/
drwx------+ 19 jeffstein staff 646 Oct 23 18:28 Movies/
drwx------+ 15 jeffstein staff 510 Jan 3 20:29 Music/
drwx------+ 90 jeffstein staff 3060 Mar 9 20:23 Pictures/
drwxr-xr-x+ 6 jeffstein staff 204 Nov 3 21:16 Public/
drwxr-xr-x 22 jeffstein staff 748 Jan 14 2012 androidTools/
-rwxrwxrwx 1 jeffstein staff 1419 Aug 28 2013 color.sh*
This is an example of ls -l here you can see color.sh has -rwxrwxrwx that means that anybody can read or write or run the file.
Without actually knowing where you installed firefox however I can't be of more help but these are some small pointers which might help.
try finding where firefox is actually installed using "whereis firefox" command.
Then try using that path in at command.
In order to get directions on how to use a command type:
man at
this will display the "manual"
DESCRIPTION
The at and batch utilities read commands from standard input or a speci-
fied file. The commands are executed at a later time, using sh(1).
at executes commands at a specified time;
atq lists the user's pending jobs, unless the user is the superuser;
in that case, everybody's jobs are listed;
atrm deletes jobs;
batch executes commands when system load levels permit; in other words,
when the load average drops below _LOADAVG_MX (1.5), or the value
specified in the invocation of at run.
So obviously you need to schedule a job with at and you can see if it worked with atq
Read the manual and it should help - if i have more time I'll write you a quick example.

how to kill the tty in unix

This is the result of the finger command (Today(Monday) when I (Vidya) logged in)
sekic1083 [6:14am] [/home/vidya] -> finger
Name Tty Idle Login Time Where
Felix pts/0 - Thu 10:06 sekic2594.rnd.ki.sw.
john pts/1 2d Fri 15:43
john *pts/2 2d Fri 15:43
john *pts/3 4 Fri 15:44
john *pts/7 - Thu 16:25
Vidya pts/0 - Mon 06:14
Vidya *pts/5 - Mon 06:14
Vidya *pts/6 - Tue 10:13
Vidya *pts/9 - Wed 05:39
Vidya *pts/10 - Wed 10:23
Under column the Tty pts/0 and pts/5 are the current active terminals.
Apart from those two pts/6, pts/9 and pts/10 are also present and I had logged into these last week. But the idle time for them is showing as "-" (not idle).
How can I kill these 6,9 and 10 terminals?
You can run:
ps -ft pts/6 -t pts/9 -t pts/10
This would produce an output similar to:
UID PID PPID C STIME TTY TIME CMD
Vidya 772 2701 0 15:26 pts/6 00:00:00 bash
Vidya 773 2701 0 16:26 pts/9 00:00:00 bash
Vidya 774 2701 0 17:26 pts/10 00:00:00 bash
Grab the PID from the result.
Use the PIDs to kill the processes:
kill <PID1> <PID2> <PID3> ...
For the above example:
kill 772 773 774
If the process doesn't gracefully terminate, just as a last option you can forcefully kill by sending a SIGKILL
kill -9 <PID>
I had the same question as you but I wanted to kill the gnome terminal which I was in. I read the manual on "who" and found that you can list all of the sessions logged into your computer with the '-a' option and then the '-l' option prints the system login processes.
who -la
You should get something like this. Then all you have to do is kill the process with the 'kill' command.
kill <PID>
for example kill pts/0
pkill -9 -t pts/0
Try this:
skill -KILL -v pts/6
skill -KILL -v pts/9
skill -KILL -v pts/10
I had the same problem today.
I had NO remaining processes, but the remaining finger entry of user "xxx",
which prevent me the deletion of this user using "userdel xxx".
Error message was: userdel: account `xxx' is currently in use.
It looked like a crashed terminal session. So I rebooted, but the issue remained.
last xxx
xxx pts/5 10.1.2.3 Fri Feb 7 10:25 - crash (01:27)
So I (re)moved the /var/run/utmp file:
mv /var/run/utmp /var/run/utmp.save ; touch /var/run/utmp
This cleared all finger entries. Unfortunately in this way even the current running sessions will be cleared. If this is an issue for you, you have to reboot, after you (re)moved the utmp file.
However in my case this was the solution. Afterwards I was able to successfully delete the user, using "userdel xxx".
you do not need to know pts number, just type:
ps all | grep bash
then:
kill pid1 pid2 pid3 ...
The simplest way is with the pkill command.
In your case:
pkill -9 -t pts/6
pkill -9 -t pts/9
pkill -9 -t pts/10
Regarding tty sessions, the commands below are always useful:
w - shows active terminal sessions
tty - shows your current terminal session (so you won't close it by accident)
last | grep logged - shows currently logged users
Sometimes we want to close all sessions of an idle user (ie. when connections are lost abruptly).
pkill -u username - kills all sessions of 'username' user.
And sometimes when we want to kill all our own sessions except the current one, so I made a script for it. There are some cosmetics and some interactivity (to avoid accidental running on the script).
#!/bin/bash
MYUSER=`whoami`
MYSESSION=`tty | cut -d"/" -f3-`
OTHERSESSIONS=`w $MYUSER | grep "^$MYUSER" | grep -v "$MYSESSION" | cut -d" " -f2`
printf "\e[33mCurrent session\e[0m: $MYUSER[$MYSESSION]\n"
if [[ ! -z $OTHERSESSIONS ]]; then
printf "\e[33mOther sessions:\e[0m\n"
w $MYUSER | egrep "LOGIN#|^$MYUSER" | grep -v "$MYSESSION" | column -t
echo ----------
read -p "Do you want to force close all your other sessions? [Y]Yes/[N]No: " answer
answer=`echo $answer | tr A-Z a-z`
confirm=("y" "yes")
if [[ "${confirm[#]}" =~ "$answer" ]]; then
for SESSION in $OTHERSESSIONS
do
pkill -9 -t $SESSION
echo Session $SESSION closed.
done
fi
else
echo "There are no other sessions for the user '$MYUSER'".
fi
You can use killall command as well .
-o, --older-than
Match only processes that are older (started before) the time specified. The time is specified as a float then a unit. The units are s,m,h,d,w,M,y for seconds, minutes, hours, days,
-e, --exact
Require an exact match for very long names.
-r, --regexp
Interpret process name pattern as an extended regular expression.
This worked like a charm.
If you want to close tty for specific user with all the process, above command is the easiest. You can use:
killall -u user_name
In addition to AIXroot's answer, there is also a logout function that can be used to write a utmp logout record. So if you don't have any processes for user xxxx, but userdel says "userdel: account xxxx is currently in use", you can add a logout record manually. Create a file logout.c like this:
#include <stdio.h>
#include <utmp.h>
int main(int argc, char *argv[])
{
if (argc == 2) {
return logout(argv[1]);
}
else {
fprintf(stderr, "Usage: logout device\n");
return 1;
}
}
Compile it:
gcc -lutil -o logout logout.c
And then run it for whatever it says in the output of finger's "On since" line(s) as a parameter:
# finger xxxx
Login: xxxx Name:
Directory: /home/xxxx Shell: /bin/bash
On since Sun Feb 26 11:06 (GMT) on 127.0.0.1:6 (messages off) from 127.0.0.1
On since Fri Feb 24 16:53 (GMT) on pts/6, idle 3 days 17:16, from 127.0.0.1
Last login Mon Feb 10 14:45 (GMT) on pts/11 from somehost.example.com
Mail last read Sun Feb 27 08:44 2014 (GMT)
No Plan.
# userdel xxxx
userdel: account `xxxx' is currently in use.
# ./logout 127.0.0.1:6
# ./logout pts/6
# userdel xxxx
no crontab for xxxx

one week information of alertlofile

I want to view the ORA errors in alertlogfile of past 7 (monday-sunday)days,
by writting in shell scripts.
Can anybody help me.
Thanks
Something like:
sed -n -e '/start_time/,/end_time/ {/ORA/ p}' logfile
or with awk
$ start="Fri Feb 27 08:00:00 2009"
$ end="Fri Mar 6 08:00:00 2009"
$ awk -v prev="$start" -v last="$end" '$0 ~ prev,$0 ~ last' logfile
A more sophisticated script looking for last date entries in ORA file is available here, but also at dba-oracle.com
This does not answer exactly your request but might give you some clues to start your own script.
I want the scripts which give output as follows (one week errors) and it should be mail to my id.
Sat Mar 14 10:30:51 IST 2009
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
Sat Mar 12 12:35:06 IST 2009
ORA-01110: data file 2: '/u02/oradata/Globe/undotbs01.dbf'
Sat Mar 10 09:54:05 IST 2009
ORA-27037: unable to obtain file status
Sat Mar 08 :15:02 IST 2009
ORA-1157 signalled during: ALTER DATABASE OPEN...
Sat Mar 07 12:35:51 IST 2009
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file

Resources