WebFaction
Community site: login faq

Hi there,

I have a simple script to restart apache and memcached. When I run the script from shell everything is working fine. But when I run it as a cronjob I get the error 'memcached: command not found'.

I think I get this error because I don't have a complete path in STARTMEM. I don't have a custom memcached app on this host.

Any suggestions on how to run this script in a cronjob without errors?

code: #!/bin/bash

USER="fp002"

DJANGO_APP="django"

PROC1="/home/$USER/webapps/$DJANGO_APP/apache2/bin/httpd"

STARTMEM="memcached -d -l 127.0.0.1 -p 39725 -m 18"
STARTAPACHE="/home/$USER/webapps/$DJANGO_APP/apache2/bin/start"
SLEEP="sleep 5"

STOPAPACHE="/home/$USER/webapps/$DJANGO_APP/apache2/bin/stop"
$STOPAPACHE

KILLMEM="killall memcached"
$KILLMEM

$STARTMEM
$SLEEP
$STARTAPACHE

asked 27 Jun '11, 08:42

mkoiter
1113
accept rate: 0%

edited 27 Jun '11, 08:46


Cron jobs run with a very limited environment, so /usr/local/bin isn't in your $PATH.

To fix this, just change the STARTMEM line to use the full path:

STARTMEM="/usr/local/bin/memcached -d -l 127.0.0.1 -p 39725 -m 18"
permanent link

answered 27 Jun '11, 08:46

David L ♦♦
1.4k13
accept rate: 45%

Thank you for this very quick reply! Solved my problem.

(27 Jun '11, 09:03) mkoiter
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×34
×17

question asked: 27 Jun '11, 08:42

question was seen: 4,759 times

last updated: 27 Jun '11, 09:03

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2021 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM