LinuxQuestions.org
Help answer threads with 0 replies.
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 08-20-2004, 09:36 AM   #1
jhill
LQ Newbie
 
Registered: Jul 2004
Location: Cheshire, UK
Distribution: SuSE 9.0
Posts: 6

Rep: Reputation: 0
cron unable to find rcapache command


I have created a script to backup my server using flexbackup. Before I perform the backup I want to ensure that all the services are shutdown. I have written a script to do this...

Code:
#!/bin/bash
#
# Script to backup server using flexbackup
#

# Stop the services before backup
rcapache stop
rcfetchd stop
rcpostfix stop
rcgroupware stop
rcwebmail stop
rcldap stop
rccyrus stop
rcpostgresql stop

flexbackup -set SLOX

# Restart the services
rcpostgresql start
rccyrus start
rcldap start
rcwebmail start
rcgroupware start
rcpostfix start
rcfetchd start
rcapache start

This script works fine when I run it from a shell. However when I run it from a cron task under root I get the following messages emailed to me...

Quote:
/backup/flexrun.sh: line 7: rcapache: command not found
/backup/flexrun.sh: line 8: rcfetchd: command not found
/backup/flexrun.sh: line 9: rcpostfix: command not found
/backup/flexrun.sh: line 10: rcgroupware: command not found
/backup/flexrun.sh: line 11: rcwebmail: command not found
/backup/flexrun.sh: line 12: rcldap: command not found
/backup/flexrun.sh: line 13: rccyrus: command not found
/backup/flexrun.sh: line 14: rcpostgresql: command not found
/backup/flexrun.sh: line 19: rcpostgresql: command not found
/backup/flexrun.sh: line 20: rccyrus: command not found
/backup/flexrun.sh: line 21: rcldap: command not found
/backup/flexrun.sh: line 22: rcwebmail: command not found
/backup/flexrun.sh: line 23: rcgroupware: command not found
/backup/flexrun.sh: line 24: rcpostfix: command not found
/backup/flexrun.sh: line 25: rcfetchd: command not found
/backup/flexrun.sh: line 26: rcapache: command not found

The crontab is set as

Code:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.22064 installed on Fri Aug 20 15:10:04 2004)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
MAILTO="root"
12 15 * * * /backup/flexrun.sh
Obviously the crontab is running the script but why can't it find the commands? Do I need to specify a path?

Thanks
 
Old 08-20-2004, 10:36 AM   #2
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
The PATH that cron is using does not include the directory containing your rc scripts. The simple fix is to put a PATH definition at the start of the script.
 
Old 08-20-2004, 11:08 AM   #3
jhill
LQ Newbie
 
Registered: Jul 2004
Location: Cheshire, UK
Distribution: SuSE 9.0
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks stickman.

When you say define a path do you mean something along the lines of this?
Code:
#!/bin/bash
#
# Script to backup server using flexbackup
#
path="/usr/sbin/"

# Stop the services before backup
$path rcapache stop
I have tried specifying the paths before each of the commands like this...
Code:
/usr/sbin/rcapache stop
but this chucks up the following errors...
Quote:
Shutting down httpd/usr/sbin/rcapache: line 158: killproc: command not found
..failed
Shutting down fetchd/sbin/rcfetchd: line 76: killproc: command not found
..failed
Shutting down mail service (Postfix)..done
Shutting down groupware..done
Shutting down webmail..done
Shutting down ldap-server..done
Shutting down IMAP/POP3 service (cyrus-imapd)..done
Shutting down PostgreSQL/usr/sbin/rcpostgresql: line 109: killproc: command not found
..failed
Starting PostgreSQL/usr/sbin/rcpostgresql: line 95: checkproc: command not found
..done
Starting IMAP/POP3 service (cyrus-imapd)..done
Starting ldap-server..done
Starting webmail..done
Starting groupware..done
Starting mail service (Postfix)..done
Starting fetchd /sbin/rcfetchd: line 66: startproc: command not found
..failed
Starting httpd [ Jserv PERL SSL ]/usr/sbin/rcapache: line 121: startproc: command not found
stty: standard input: Invalid argument
..done
I think there is something I am not understanding about paths here
 
Old 08-20-2004, 12:21 PM   #4
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
For starters, the variable is "PATH" not "path". This variable defines the sequence of directories to search for executables. If the commands work in your shell environment, then do the following:
echo $PATH

Then put a matching PATH definition in your script:
PATH=output from above command
export PATH

In addition, you don't want to specify the PATH as just a single directory (ie /usr/bin) unless you only want to look in just that one directory.
 
Old 01-15-2010, 06:35 AM   #5
Tm Tecnos
LQ Newbie
 
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
flexbackup process launched by crontab

Hello guys
dunno if this can help, hopefully you solved already.
Just wanted to gime my 2 cents of experience.

I had the same problem under Ubuntu and I found that, probably after an update of Ubuntu, there was a difference between the PATH= line in crontab and the PATH of the root user for an interactive login, this was what made my flexbackup script working perfectly in interactive mode but not when launched by crontab.

I checked the PATH of the interactive root shell this way:
sudo bash
echo $PATH

Then I updated the PATH= line at the beginning of the /etc/crontab file with the same settings as before and everything started working again.

Tom
 
  


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
cron command alphamike Linux - Newbie 2 08-28-2005 12:04 AM
unable to run cron job fahad26 Linux - General 3 06-30-2005 01:51 AM
annoying cron job on find, how to get rid of it feetyouwell Linux - Software 2 06-27-2005 08:44 PM
Help with a cron command phatboyz Linux - Software 2 01-19-2005 11:09 AM
New to cron programming: need to find a good tutorial lhoff Programming 1 03-31-2002 02:00 PM


All times are GMT -5. The time now is 02:50 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration