Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am a Unix/Linux n00b. I have a VPS running CentOS with WHM/cPanel. I comissioned the installation of ASSP Deluxe, which is a third-party anti-spam solution. Everything works great.

One of the cronjobs configured by ASSP Deluxe is a PHP script that looks up the list of domains/subdomains installed on the server and automatically rebuilds a plain text file with a list of these domains, one per line.

The cron entry in question is this:

*/59 * * * * /usr/local/cpanel/3rdparty/bin/php-cgi /usr/local/assp/deluxe/ex_localdomains.php

What I need to do is add a fixed extra line manually to the end of this file with the list of domains. Doing it manually with a text editor works, but as the cronjob runs every hour, my line is wiped out every hour.

The easy way would be to add some code to the end of the executed PHP file to do this, but the PHP file is ionCube-encoded, so that is a no go.

Instead, I have created a PHP script that appends a line to the end of the file. Executing this command in this way through SSH (root logged in)...

/usr/local/cpanel/3rdparty/bin/php-cgi /usr/local/assp/deluxe/add_manual_domain.php

...works great! It adds the line I need to the end of the file. So I amended the cronjob in crontab (crontab -e) to the following:

*/59 * * * * /usr/local/cpanel/3rdparty/bin/php-cgi /usr/local/assp/deluxe/ex_localdomains.php && /usr/local/cpanel/3rdparty/bin/php-cgi /usr/local/assp/deluxe/add_manual_domain.php

I assumed this would perform the rebuild, and then run my script to add the line to the end of the file once the rebuld completes.

However, it doesn't do this. The file is rebuilt successfully, but the extra line is not added to my file. Running my little PHP script manually from command line, however, works.

Can anyone shed some light on this?

share|improve this question
    
Try replacing the '&&' with ';' in the crontab line (without single quotes). If you use '&&', shell will execute the other command only if the exit code of the first is zero (it should be, but...). Also, I assume this is root's crontab you are talking about. –  O G Sep 5 '11 at 14:07
    
BINGO! "&&" to ";" did the trick. Gracias. –  RCWH Sep 5 '11 at 14:19
add comment

1 Answer

The && is probably interpreted differently by the cron handler than expected. (Without knowing which cron-software is used I can't tell exactly what is happening...)

Just write a new 2 line script contain both the PHP commands (each on its own line). Actually, in this script you might just as well cat both files together instead of using PHP the add the extra lines.

Then run this new script from cron in stead of the current cron-line.

Much easier that way.

P.S.: Don't forget to set the permissions on the script to "Execute"

Edit: Just saw the comment from OG. ";" might work, but (like &&) it depends a bit on exactly how the crontab handles things.

share|improve this answer
    
OG was spot on. Thanks for your suggestion though. –  RCWH Sep 5 '11 at 14:20
    
The && and ; are interpreted by the shell and work as you would expect - run the second command if the fist exits with status 0 (&&) or to run the second command after the first (;). –  Iain Sep 5 '11 at 14:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.