LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-29-2014, 11:38 PM   #1
thebusymind
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Rep: Reputation: Disabled
Cron is being mean :(


Hey Guys,

This is the most frustrating problem I've had in a while. I have an Elastix PBX running on CentOS 5.10. Everything works perfectly - except this Cron job:

*/1 * * * * /var/www/html/calls.sh

here's the script:

#! /bin/sh
file="/var/www/html/calls.txt"
if [ -f "$file" ]
then
rm /var/www/html/calls.txt
touch /var/www/html/calls.txt
chmod 777 /var/www/html/calls.txt
asterisk -rx 'core show channels' | grep -m1 "call" | cut -d' ' -f1 >> /var/www/html/calls.txt
else
touch /var/www/html/calls.txt
chmod 777 /var/www/html/calls.txt
asterisk -rx 'core show channels' | grep -m1 "call" | cut -d' ' -f1 >> /var/www/html/calls.txt
fi

When I run this manually in a terminal, it does exactly what I want it to - however, when Cron runs it, it will create the calls.txt file, but it does not write anything to it. The server only has one user (root) and when I created this, I created it as root.

Can someone help?

Thanks!
 
Old 07-30-2014, 12:39 AM   #2
thebusymind
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Nevermind - Specifying the path fixed this:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
 
Old 07-30-2014, 01:04 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,590

Rep: Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353
so please mark the thread solved. The problem was I think the cron job cannot find the command asterisk. You ought to use all the commands using full path in cronjobs.
 
Old 07-30-2014, 02:09 AM   #4
qrange
Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 994

Rep: Reputation: 47
I think the problem is that cron 'ignores' all ENV variables.
 
Old 07-30-2014, 03:12 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,590

Rep: Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353
No that is not a problem at all. It is designed to do that.
 
Old 07-31-2014, 01:34 AM   #6
qrange
Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 994

Rep: Reputation: 47
so its a design flaw. :P
 
Old 07-31-2014, 01:41 AM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,346
Blog Entries: 11

Rep: Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310Reputation: 3310
Quote:
Originally Posted by qrange View Post
so its a design flaw. :P
No, it is a design constraint.
 
  


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
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 03:37 PM
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 09:57 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 02:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 02:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:19 PM.

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