Cron restarting problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron restarting problem
# 1  
Old 02-11-2004
Cron restarting problem

Hi I have a script on Solaris 5.6 to restart cron /etc/init.d/cron. I have trouble restarting cron. It's all beacuse of the line:
pid=`/usr/bin/ps -e | /usr/bin/grep cron | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
which returns not null. This is because of the system return two process which are belong to:
/etc/init.d/cron
/usr/bin/grep cron

Dows any one know how to fix this problem.
Code:
#!/bin/sh
#
# Copyright(c) 1997, by Sun Microsystems, Inc.
# All rights reserved.
#
#ident  "@(#)cron       1.11    97/04/16 SMI"   /* SVr4.0 1.3.3.1       */

#       cron control
pid=`/usr/bin/ps -e | /usr/bin/grep cron | /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`

case $1 in
'start')
        echo "$pid";
        if [ "${pid}" = "" ];
        then
                /usr/bin/rm -f /etc/cron.d/FIFO
                if [ -x /usr/sbin/cron ]
                then
                        /usr/sbin/cron
                fi
        fi
        ;;
'stop')
        if [ "${pid}" != "" ]
        then
                /usr/bin/kill ${pid}
        fi
        ;;
*)
        echo "usage: /etc/init.d/cron {start|stop}"
        ;;
esac

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 03:23 PM..
# 2  
Old 02-11-2004
Typing to the page is awfully slow

One comment is that typing to the page is awfully slow. Is there any way to improve this?
I have to type this line like fifteen seconds before I can see it appear on my screen...
# 3  
Old 02-12-2004
Not sure about the answer to your first post, but as far as being slow, if you're using the unix.com theme with the flash file at the top, then go here and select a new theme; otherwise, I'm not sure why it seems to hang.
# 4  
Old 02-12-2004
Try this

There is always a better way, but here is an idea.

grep out the grep process.

so it looks like this now:


pid=`/usr/bin/ps -e | /usr/bin/grep cron | /usr/bin/grep -v grep | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`

Last edited by viRaven; 02-12-2004 at 01:31 PM..
# 5  
Old 02-12-2004
Try this:
pid=`/usr/bin/ps -e | /usr/bin/grep [c]ron | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`

[c]ron is a regular expression that will match "cron" but does not match itself.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

2. Shell Programming and Scripting

Please help me in cron problem

When i am working with cron i given the command as crontab - e | grep runjob.sh.I though my command is wrong and i closed it by ctrl+D.After that when i need to open the cron with crontab -e its not opening its giving some number 22667 and when i given crontab -l its working fine i can see all... (5 Replies)
Discussion started by: bhas85
5 Replies

3. AIX

Problem with IP address when restarting AIX

Hi! I have useud SMIT to configured my static adress for AIX but when I restart the AIX the ipadress is not shown when I print netstat -in or ifconfig -a. I have to configure the ip whit smit to have it start! How can I starting the ip during boot? (6 Replies)
Discussion started by: peter.olofsson
6 Replies

4. Shell Programming and Scripting

Problem with Cron

Hi i am new here and have a quick question. i am receiving ./project.sh: line 12: syntax error near unexpected token `newline' ./project.sh: line 12: `echo "`date +"%F %R"` `md5sum /etc/passwd`" >> ' error message here is my script. could you please help! #!/bin/bash # PROGRAM:... (4 Replies)
Discussion started by: mas1888
4 Replies

5. UNIX for Dummies Questions & Answers

cron problem

I'm using Red Hat and I need to get cron working and I'm not sure what the problem is. As a test I've done the following: 1) In /etc/cron.d I've created a file called date with the following contents 2) */1 * * * * root date >> /root/thedate 3) This works perfectly. It sends the date every... (1 Reply)
Discussion started by: kerpm
1 Replies

6. UNIX for Advanced & Expert Users

How to solve restarting problem

Hi! My unix os version is OSF1 CP1 V4.0 878 alpha. It startup normally but it restarts within 5 sec. I would like to know how to solve . Please reply to me. Thanks . akzin (2 Replies)
Discussion started by: akzin
2 Replies

7. UNIX for Dummies Questions & Answers

Cron problem

Hi, I've just done a school boy error. I was trying to edit the crontab but instead of using: crontab -e I used crontab -r without realising. Then went to look at the crontab but ntohing their. Looked int he manual and -r removed the crontab. Is their any way of getting this back?? ... (3 Replies)
Discussion started by: tez
3 Replies

8. UNIX for Dummies Questions & Answers

Cron problem

Hi, I want to run my shrip for every 30 min.. if i enter crontab -l i am getting following.. 00,10,20,30,40,50 * * * * /home/arbuser/temp2/perform/per.sh 00,15,40,35,50 * * * * sh home/arbuser/temp2/perform/per.sh if I enter like this : ps -ef |grep cron root 311454 1 0... (3 Replies)
Discussion started by: redlotus72
3 Replies

9. UNIX for Dummies Questions & Answers

cron problem

In freebsd when I do crontab -l I get the result crontab:no crontab for root,yet I have a crontab in /etc and I don't know what got messed up? It was working the other day? I probably messed something up(I'm blaming me,the user). I've been wanting to have hourly emails(to my home email and not... (2 Replies)
Discussion started by: VPN
2 Replies

10. UNIX for Dummies Questions & Answers

Cron problem?

here's the scoop.. I have a ksh shell script written, that when I run it manually, it works wonderful, when I let it run via cron, it runs (tells me I have it set up correctly) but yet it doesn't run correctly (it only runs part of the commands with the script). what gives? I've got the... (4 Replies)
Discussion started by: hedrict
4 Replies
Login or Register to Ask a Question