LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-16-2009, 06:11 AM   #1
henkoegema
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Rep: Reputation: 0
How to make my cron job run ?


To make vTigerCRM working with my Asterisk PBX I start a php script (AsteriskClient.php):

root@MSI:~$ cd /var/www/vtigercrm/cron/modules/PBXManager/
root@MSI: /var/www/vtigercrm/cron/modules/PBXManager$ ./AsteriskClient.php


Above script is OK.
(This script must be kept running.....)
So I leave a terminal window open for the script to run

Questions:
1. Why can't I do this with one command?
root@MSI:~$ /var/www/vtigercrm/cron/modules/PBXManager/AsteriskClient.php


2. It looks like this script can't run in the background with &.
Why not?

root@MSI:/var/www/vtigercrm/cron/modules/PBXManager$ ./AsteriskClient.php &


3. To do this automatic 'at boot' I made a crontab :


root@MSI:/var/www/vtigercrm/cron/modules/PBXManager# crontab -l
@reboot cd /var/www/vtigercrm/cron/modules/PBXManager/
@reboot ./AsteriskClient.php

This doesn't seem to work either, because the php script doesn't start. (or starts and stops at once?)
 
Old 12-16-2009, 06:56 AM   #2
kubaPL
LQ Newbie
 
Registered: Apr 2009
Location: Poland
Distribution: Fedora
Posts: 6

Rep: Reputation: 0
hi,

for starters, the @reboot lines need to be in one line. each line is executed in a seperate process so the "cd" will be in the context of the first process and the ./Asterix.php will be in another context. so when the second line is run it will not be run in the directory that you are expecting.

if you want to do it in this way, add both lines to a bash script and only add that one script to the crontab

i.e.
@reboot /root/startasterix.sh

but, this line should work
root@MSI:~$ /var/www/vtigercrm/cron/modules/PBXManager/AsteriskClient.php
my guess is that from the perspective of the cron process either the php binary is not visible or your php file is missing the #! shell interpreter line (or both)

try something like this on the first line of your php file
#!/usr/local/bin/php -q
of course update the path to match that of your php installation.
 
1 members found this post helpful.
Old 12-16-2009, 06:45 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
By default cron has a minimal PATH setting, so it's recommended to always specify absolute/full paths to all cmds & files referenced.
Also, it does not default to the user's home dir, so don't use './blah'.
As said above, put the cmds in a script, full paths and (if reqd) set the reqd PATH in the script.
 
1 members found this post helpful.
Old 12-17-2009, 04:57 AM   #4
henkoegema
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
@kubaPL & chrism01:

Thanks for your answers.
 
  


Reply



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
Run cron job in every 20 second ust Linux - Newbie 13 01-15-2015 01:01 PM
How do I make a cron job run "every two weeks"? Seventh Linux - Newbie 12 01-13-2006 11:55 AM
how to run this cron job ashley75 Linux - General 5 05-24-2004 11:20 AM
Did my Cron job run? ryedunn Linux - Newbie 2 02-25-2004 08:59 AM
Cron job does not run brentos Linux - General 6 12-12-2003 02:37 PM

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

All times are GMT -5. The time now is 07:30 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
Open Source Consulting | Domain Registration