Why service (start|stop) can not be called from cron?


 
Thread Tools Search this Thread
Operating Systems Linux Why service (start|stop) can not be called from cron?
# 1  
Old 11-01-2010
Why service (start|stop) can not be called from cron?

Hi,

When I googled, I came to know that I can not call the command
"service <service-name> start" from cron, insted I have to specify path to the service-name.

I wanted to know the reason.


Thanks,
Hansini
# 2  
Old 11-01-2010
have you tried running it with the full path to the command "service?" when you are running things in cron, you do not have a full environment unless you source one. Things that work for a user will not work in cron as a result.

Also, it is a good practice to not use the "service" command in a script. Instead, you should use the init script itself such as:
Code:
/etc/init.d/somedaemon start

# 3  
Old 11-01-2010
Thanks! Mark.

Yes I tried by specifying path to the init script in cron. I wanted to know why. Now I got the answer.
# 4  
Old 11-17-2010
Maybe the service command can't found, try to use /sbin/service ..

If it works, you need to add PATH env variable in cron job.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Not able to start cron service in Solaris 10

Hi, This is Solaris-10 x86. I am not able to start cron service, configured in FMRI. It is in maintenance and when I clear it, it seems like calling and failing on /etc/init.d/tcs-rtm script. I am not able to figure out, why cron is calling that script, if this failure is because of that. Cron... (5 Replies)
Discussion started by: ron323232
5 Replies

2. AIX

To stop ftp service on VIO

Hi all, How can I close ftp port 21 on VIO server. Best regards, ---------- Post updated at 10:06 AM ---------- Previous update was at 08:45 AM ---------- I resoved with switch to OS mode. $ oem_setup_env (0 Replies)
Discussion started by: getrue
0 Replies

3. Red Hat

Would like to stop service authentication

Hello All. I'm trying start services as an Admin user on CentOS 7. I'm able to start the service as the user but it prompts me for a password. How do I get the user to start a service without being prompted? For example; If I attempt to start the sendmail service as my user2, I receive the... (2 Replies)
Discussion started by: bbbngowc
2 Replies

4. Shell Programming and Scripting

Cron VPN Client start/scp/stop

Hi, Anyone can help me on how my script will run on crontab, When I manually run my script, it work. But when I put in cron didn't work. #crontab schedule 00 16 * * * /home/scriptdir/myscript.sh # myscript.sh #!/bin/bash echo "mypassword"| sudo -S /etc/init.d/vpnclient_init start cd... (2 Replies)
Discussion started by: fspalero
2 Replies

5. AIX

Q: how to start a service when system start

As topic, assume we have a service called "blahservice" and we can start it by: startsrc -s blahservice what is the best practice to run such command when system start? - directly use mkitab to add it into /etc/inittab or - drop startup scripts in /etc/rc.d/rcX.d I know they... (4 Replies)
Discussion started by: acerlinux
4 Replies

6. Shell Programming and Scripting

Script not working when called by cron

Hello, I have the following script which works fine when ran from the command line: #!/apps/python/2.3.4/bin/python import os import sys import time user = os.getenv("USER") string = time.strftime("%m%d%y0000 " + user, time.gmtime()) However, when I have this run by crontab, I... (4 Replies)
Discussion started by: cooldude
4 Replies

7. Solaris

How to start/stop cron jobs on live server

Hi, I am working with a company where some times i need to start/stop cron jobs on need basis. I have one option to kill cron daemon.Is it right? Please correct me. Waiting for your reply. Thanks in advance.. (2 Replies)
Discussion started by: varaprasadu
2 Replies

8. AIX

How to stop perl service

how to stop perl service on AIX? how to find if per service runing? (4 Replies)
Discussion started by: rainbow_bean
4 Replies

9. Shell Programming and Scripting

How to determine the script is called from CRON?

Hello expert, What I want is to determine whether the script is called from CRON or it is executed interactively? I tried the following but no luck: #!/bin/ksh cronID=`pgrep -x cron` GPID=`ps -ef -o ppid,pid | grep " $PPID$" | awk '{print $1}'` if ; then echo I am being run... (15 Replies)
Discussion started by: wes_brooks
15 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question