LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-27-2011, 02:33 AM   #1
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
cron job


Hi

i am using centos 5.5
i have a couple of cron jobs running, some of them take about 20min to execute, i need to check the status of this jobs running. if they are currently being executed or they finish executing.

i went on the net there is a command "jobs". can this be used ,how to use it.

please help
 
Old 02-27-2011, 02:49 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Also found on the net:
Quote:
jobs -x command [ args ... ]
The first form lists the active jobs. The options have the following meanings:
-l
List process IDs in addition to the normal information.
-p
List only the process ID of the job's process group leader.
-n
Display information only about jobs that have changed status since the user was last notified of their status.
-r
Restrict output to running jobs.
-s
Restrict output to stopped jobs.
If jobspec is given, output is restricted to information about that job. The return status is 0 unless an invalid option is encountered or an invalid jobspec is supplied.

If the -x option is supplied, jobs replaces any jobspec found in command or args with the corresponding process group ID, and executes command passing it args, returning its exit status.
I never used it so cannot indicate what it does or how it exactly works. I think since it's a job launched by cron you'd better check using pidof:
Code:
pidof name_of_your_command
to see if process IDs are still used by your script/command. On the other hand you could include a line in your script that writes something to a file in /tmp when done (for example date and time). Then by checking that file you'll know if your job is completed or not.

Kind regards,

Eric
 
Old 02-27-2011, 04:56 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
The cron daemon already logs starting jobs in /var/log/cron. So you could include a line "logger -p cron.info -t "Starting jobname $$";" near the top of the cronjob and "logger -p cron.info -t "Exiting jobname $$";" near the end. The "$$" is the PID of the cronjob shell script, so any processes it starts should have their $PPID value set to this which makes it easier to search for using 'pgrep -lP $PPID'. Another reason to favor 'pgrep' over 'pidof' is that pgrep can use wildcards so running for instance 'pgrep -l cro*' will list any process that has the string "cro" in its process name. Finally, if you don't want to or can't modify your cronjob(s) but you can edit /usr/bin/run-parts and your cronjob or jobs are part of one of the default /etc/cron.{hourly,daily,weekly,monthly} directories /etc/crontab runs you could edit /usr/bin/run-parts to include logging jobs (in kinda-like-diff style):
Code:
        if [ -x $i ]; then
+               case "${i//*\//}" in
+                       *backup*|*audit*) logger -p cron.info -t "Starting job "${i//*\//}"";;
+               esac
The only drawback is that you need to track changes as /usr/bin/run-parts will be overwritten on upgrade of the crontabs package.
 
1 members found this post helpful.
Old 02-27-2011, 09:12 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Thanks for pointing out pgrep unSpawn, yet learned something new :-)

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need help with cron job Totoro-kun Slackware 4 11-07-2010 09:54 AM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron job Thulemanden Linux - General 1 11-06-2006 12:40 PM
cron job working2hard Programming 6 07-28-2004 10:12 PM


All times are GMT -5. The time now is 06:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration