Script to get hung jobs in cron service.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to get hung jobs in cron service.
# 1  
Old 11-24-2010
Script to get hung jobs in cron service.

Hi
I want to have a list of hung jobs in crontab .
e.g
The below output gives a list of hung jobs including the running one.

"
Code:
USER1] ps -ef | grep 22345
root 22345 1 0 Nov 10 ? 0:09 /usr/sbin/cron
user2 1061 22345 0 Nov 11 ? 0:00 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 20456 29535 0 09:49:41 pts/5 0:00 grep 22345
oracle 3436 22345 0 05:00:01 ? 0:00 sh -c /d002/oracle/dbrun1.sh
oracle 19920 22345 0 00:01:00 ? 0:00 sh -c /d002/oracle/common/dbatools/alertscan.sh /d002/oracle/common/dbatools/al
user2 18201 22345 0 Nov 11 ? 0:00 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 3400 22345 0 Nov 13 ? 0:00 sh -c /d002/oracle/dbrun2.sh

"
Now the output of the script should be as follows.
Code:
 
user UnixPorcess obName
---- ----------- -------
user2 1061 sh -c /u01/user2s/b7111/movecsv.ksh
user2 18201 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 3400 sh -c /d002/oracle/dbrun2.sh

Can you please help me to write a shell script to get the required output.

So point to be noted here is output should not contain
"1) Today's job list, 2) grep command process(e.g 20456) and the process which is running from root user (root 22345)

Thanks in Advance.

Last edited by Scott; 11-24-2010 at 02:50 PM.. Reason: code tags please!
# 2  
Old 11-24-2010
Quote:
Originally Posted by abdul bari
So point to be noted here is output should not contain
"1) Today's job list, 2) grep command process(e.g 20456) and the process which is running from root user (root 22345)
Code:
ps -ef | 
awk -v d="$(date +"%b %d")" '/22345/ && !($0 ~ d) && !/grep/ && !/root/'

# 3  
Old 11-24-2010
OK trick is to spot STIME column with the "Mth dd" format (and ignore hh:mm:ss).
I assigned cron process id (22345) to an awk var as I'd assume you are fetching this PID already in your script and would want to pass it to awk.

Code:
$ ps -ef | awk -v PP=22345 '$3==PP && $0 !~ "[0-9]:[0-9][0-9]:[0-9]" {
 printf $1" "$2 ;
 for(i=9;i<=NF;i++) printf " "$i;
 printf "\n"
}'
user2 1061 sh -c /u01/user2s/b7111/movecsv.ksh
user2 18201 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 3400 sh -c /d002/oracle/dbrun2.sh


Last edited by Chubler_XL; 11-24-2010 at 06:22 PM.. Reason: Update to skip hh:mm:ss ps lines
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to Delete Old Cron Jobs

I have a cron entry to deploy a website portal from a staging server to a series of production servers on a weekly basis. On occasion, a random office worker who knows nothing about Linux let alone cron, will be tasked to update news picks on the staging server and then run a manual deployment... (2 Replies)
Discussion started by: AndrewT
2 Replies

2. Solaris

Cron jobs and at jobs

There are two jobs in Solaris , Cron and at jobs.. I know how to disable or enable cron jobs. How can I enable at jobs and disable it. Kindly help. Rj (2 Replies)
Discussion started by: jegaraman
2 Replies

3. Linux

Cron jobs

Hi, I am a Linux administrator (newbie) in my company. The distro being used in the servers here is Centos 5.3 Just need to know, as a Linux administrator is it better for me to use /etc/crontab to set my cron jobs. I do not want to use the crontab -e to schedule my cron jobs. That means... (1 Reply)
Discussion started by: anaigini45
1 Replies

4. Shell Programming and Scripting

General Q: how to run/schedule a php script from cron jobs maybe via bash from shell?

Status quo is, within a web application, which is coded completely in php (not by me, I dont know php), I have to fill out several fields, and execute it manually by clicking the "go" button in my browser, several times a day. Thats because: The script itself pulls data (textfiles) from a... (3 Replies)
Discussion started by: lowmaster
3 Replies

5. Solaris

cron jobs

how to Put a cron entry which should be same script triggered on every Saturday and 1st of every month at 01.00 GMT. 0 2 1 * 6 --( At 2.00 GMT every sat & on 1st of every month) the above syntax is correct? Thanks (1 Reply)
Discussion started by: kurva
1 Replies

6. UNIX for Advanced & Expert Users

cron jobs...

I need to start a job every friday night at 8:00 P.M , it runs all the day on Sat and Sun....can somebody tell me how to do this...I understand crontab...but haven't used it.........can u write some steps.....how to create a file and call.....I honestly dont know? Plz help.Thanks (2 Replies)
Discussion started by: RubinPat
2 Replies

7. UNIX for Dummies Questions & Answers

Error while running the script through cron jobs .Please help me on this

Hi Everyone, I have written a korn shell script to shutdown my documentum docbase server and to restart it automatically on a weekly basis. My script is, When i execute this script manually, i was able to execute it successfully without any issues. I have scheduled this script in cronjob... (1 Reply)
Discussion started by: Sheethal
1 Replies

8. HP-UX

Cron jobs

i am new for cronjobs can someone please tell me what logic is behind these RED Numbers and stars below? --> crontab -l 00 1 * * * /home/scripts/TarprodContent > /tmp/MprodBkup.log 2>&1 00 1 * * * /home/scripts/TarTprodContent > /tmp/TprodBkup.log 2>&1 00 1 * * *... (5 Replies)
Discussion started by: ajadaun
5 Replies

9. UNIX for Dummies Questions & Answers

CRON Jobs

Hi, I am a total newbie to all things Unix. I've worked out I need to set up something that will allow me to automatically backup a DB for me, the DB is for a foum system I run. Now, I've only found out I need to use telnet for this, and worked out hwo to log into telnet today. From here... (4 Replies)
Discussion started by: eludlow
4 Replies
Login or Register to Ask a Question