Cron Job uses old non-existent php file - php

I'm working with Yii and have to implement a script for cron.
I've got a script file, which just calls Yii and starts my php-script file.
Until this point everything is fine. If I'm updating the php-script, Cron just continues executing the old one.
Restart of cron-service, reboot of the server etc didn't help.
I also uninstalled cron and installed it again, but nothing changed. He still executes the old version of this php-script.
Anyone an idea what's wrong or what I could do to solve this? I'm using Ubuntu 12.04.
EDIT:
The cronjob script is running:
#!/bin/bash
cd ../www/protected/ ./yiic Cron ProcessPayments
The php-script
class CronCommand extends CConsoleCommand {
public function actionProcessPayments() {
...
}}
This works, but any change I make on this script is ignored by Cron.
And now I'm on this point: he executes both. My old version and the new version. I've never been this confused by something.

Assuming you have sudo on the machine it's located on...
First check to see if it's located in the usual cron directories /etc/cron.*
sudo find /etc/cron* -mount -iname yiic
If nothing shows up there then search the entire filesystem because otherwise you'll start having to search a lot of other places manually and it takes more time than running a find
sudo find / -mount -iname yiic
In both find commands if the filename is or has ever been anything other than yiic do yiic* so that it searchs for anything that starts with yiic
Once you have found the copies, if there are any others, remove every single one except the newest one, or even that one and then reinstall the script on the machine from version control.
Edit:
Probably more than you really care about, but the find command breaks down like this:
sudo - elevated priviledges so you can search everywhere as opposed to where you're user can read
find - command to look for thigs
/ - the starting point for the search, can be anywhere
-mount - this tells find not to search other filesystems
-iname - case insensitive name to search for
yiic - the search term

Locate all your copies of the script using the find command and delete those copies not needed. Restart cron after you have chosen the copy of the script you want to execute. My guess is a copy of the script might be hanging around in a directory (e.g. config.daily or something similar).
HTH

I had a similar problem. A script in /etc/cron.d was still executed in the old fashion after modifying it. I solved the problem by sending a SIGHUP to cron:
sudo pkill -SIGHUP /usr/sbin/cron

Related

Cronjob to detect last modified files

I want to run a cronjob every minute to detect all files that were changed in the last minute in a specific directory (with about 300.000 inodes) and export this file list to a csv.
Is it possible to run an optimized command to do that? I cant run a "find" with sort flag in this directory cause it is huge and it will probably take more than 1 minute to run all files.
Is there any command I can do that? Or run any specific program on the background of the server that logs every changed file as it is changed? If there is a command using PHP to do this I am fine, I can create a cron to execute a PHP script, no problem.
There is a Linux utility called incron that can be used similar to normal cron, but rather than events being time based, they work off of inotify and are fired from file events.
You can find the Ubuntu man page here: http://manpages.ubuntu.com/manpages/intrepid/man5/incrontab.5.html
I personally have not had to use it for anything too complex, but it roughly goes like this:
Install it:
sudo apt-get install incron
Open the editor to add an entry:
incrontab -e
Put something like this:
/var/www/myfolder IN_MODIFY curl https://www.example.com/api/file-updated/$#
The first part is the file or folder to watch. The second part is the event. And the third part is the command.
I think that $# is the placeholder for the file in question.

Path is not available in PHP exec or shell_exec

I've been trying and searching about a small issue I have in our php application. We use a which to find the full path of a program, however it returns with
which: no bla in ((null))
on Centos, on our own debian boxes it works just fine. I've figured out since then that (obviously) the PATH is not available in the shell from PHP. But what I can't find out is why that is the case. I've replaced the command with all sorts of commands to find out what the environment is in which I run in.
If I run an echo $PATH I actually see the directories I've set in the .bash_profile. If I run echo $SHELL I know I am using bash, if I run whoami I found out I am not the apache user but a different user, whom I changed the .bash_profile for. As I've read there's a difference between shells, so I thought it might not load the .bash_profile so I've also added the export PATH to the .bashrc.
I can get it to work with a change in the code, I could replace the which, but I am just genuinely interested in why this is not working on this centos configuration. I've now added an export PATH in the exec function before the which and it works, and should also work on other systems, but still I think it shouldn't be necessary.
Anyone know what could cause this behaviour?

Can't get PHP Command Line Script to execute without prepending 'php' despite shebang added and path to symlinked executable added to PATH

I'm trying to create something similar to the laravel installer, it's a PHP Script that utilises Symfony's Console Component. It all works fine except I can't seem to get the damn thing to execute globally on my command line.
I've currently got the script(boiler) stored as /dir/dir/vendor/author/packagename/boiler.
Via Composer I also have a symlink that points to the script from /dir/dir/vendor/bin/. Automatically done via bin in composer.json.
I've updated my $PATH, which now shows /folder/folder/vendor/bin/ to point to the symlink;
My script starts:
#!/usr/bin/env php
Permissions are:
-rwxr-xr-x
I'm running Zshell on Mac OSX.
It will run if I go into the directory and type php boiler but boilerreturns command not found and if I'm in a different directory boiler also returns command not found. php boiler returns "Could not open input file: boiler"
The laravel installer runs exactly as I want mine to, using just laravel whilst anywhere on the command line.
At a complete loss. Google isn't turning up any similar issues, and neither is Stack (My searching ability may be lacking though, it's 4am.)
For those with similar issues:
Use which commandName to see if it's correctly added to your $PATH
Check the symlink is correct if it's via one
Check permissions on symlink and executable script
Post to stackoverflow so that it'll just.. fix itself.
So... which boiler returned the correct path so I tried boiler again from my home dir and it worked.
I genuinely haven't changed a single thing and been stuck for an hour. I don't understand...
Thanks all for help.

Running PHP script with Crontab (Plesk / CentOS6)

As a customer in Plesk, I am attempting to run:
php -q /httpdocs/_external/export/test.php
From this tutorial: http://daipratt.co.uk/crontab-plesk-php/
I'm receiving the error
"php: command not found"
Is there something I need to enable from the main user or a different command I would need to use to run the script?
(also tried /bin/php with no luck, there is no php file in that dir)
"which php"
-/usr/bin/php
(when I use this dir I also get "no such file or dir" I guess since when I use / it's pulling from the customers root not the server root)
This answer will help you. My understanding is that Cron runs everything relative to itself, so you should always use absolute paths when running something from Cron.
Good luck, and happy holidays!

PHP script on my MAMP testing server can't access node_module: less

I'm trying to configure my local development environment to read .less files so that I can edit .less files during development and only convert to .css when it's time to go live. Make sense?
I'm running MAMP as my local testing server. I'm following the instructions I found here:
http://programming-perils.com/155/parse-less-files-on-the-fly-and-serve-them-as-css/#comment-920
In short, the plan is to use an htaccess file catch requests to .css files and direct them to a PHP script which compiles the .less file of same name and returns the css code.
Everything seems to be working from the command line. I can compile a .less file from the command line and it spits out the css. I know my rewrite rule is working because I can type the url into a browser and see the output of my php script. For example, if my PHP script calls echo shell_exec('pwd'); I will see a path printed in the browser.
THE PROBLEM is that I can't get the less script to run unless I SSH to the localhost as root. When I exit SSH and run the command I get "Permission denied". I suspect this is what happens when my PHP script tries to call this... so it's returning nothing.
I guess the question boils down to how can I get my PHP script to run the less compiler?
UPDATE! I solved the problem...
It turns out that the less command (path/path/lessc) needed to be sudo'ed. PHP wasn't doing this, so the shell_exec() command wasn't returning anything. That's why my echo statements DID work.
There are a lot of ways to sidestep this, but I determined that editing the list of sudoers with sudo visudo was the best for my purposes. There was a lot of helpful tips on this post. Through trial and error, I figured out that PHP uses the www-data account. Adding this line fixed my problem:
www-data ALL=(ALL) NOPASSWD: /var/root/node/npm/node_modules/less/bin/lessc
Something to remember is that you STILL have to add sudo to the command that gets fed to shell_exec(). Hope this is helpful to someone else.
Maybe it would be easier if you'd use the PHP implementation of lesscss: lessphp
It turns out that the less command (path/path/lessc) needed to be sudo'ed. PHP wasn't doing this, so the shell_exec() command wasn't returning anything. That's why my echo statements DID work...
See my edits to the question above.

Categories