I'm trying to run a Ant build.xml file via a cronjob. I have seen that i can run system commands with php and wondered whether these could be used to run the ant build file? If so i can then setup a cron job to run the php file every night?
Does anyone know whether this is possible?
For instance i have the following in my php file:
system("ant ./build/cronjob/build.xml");
Although this produces output it doesn't appear to be working?
Has anyone else come across this?
First step is to ensure you can run ant ./build/cronjob/build.xml from command prompt. Creating cron entry will be then straight forward.
I prefer creating a wrapper script, say $HOME/scripts/callant.sh. The script could be like
#!bash
#setup variables
BUILD_FILE=/build/cronjob/build.xml
ANT_CMD=/pathtoant/bin/ant
JAVA_HOME=<path to jdk>
#setup path
#setp LD_LIBRARY_PATH ..
$ANT_CMD -f $BUILD_FILE > /tmp/$$out.log 2>/tmp/$$err.log
Related
I have 2 .php files in my application - book.php and weather.php. I create a file named "runscript" in /.openshift/cron/minutely. This file contents:
#!/bin/bash
php -f $OPENSHIFT_REPO_DIR/weather.php
This script send me message to phone every minute, it's OK.
Then I replace to:
php -f $OPENSHIFT_REPO_DIR/book.php
This script MUST send me message too, but nothing is happing. But if I just run this script by my webbrowser (go to the http://xxx-xxxxxxx.rhcloud.com/book.php) so I got my message. How is it possible? Magic?
Did you miss the #!/bin/bash part? That's needed to run the shell script.
For why your cron job is not executing, check the cron logs on OpenShift. You can find them at ~/app-root/logs/cron_*.log when you SSH into your gear.
Make sure your cron job is execuable with chmod, and has the shebang line as #gnaanaa says. Also check if you have one of the .openshift/cron/minutely/jobs.{allow,deny} files as they may cause cron to skip your job. (See the cron README for more information.)
And after your cron job is working, you can get rid of the wrapper script runscript and have cron call book.php directly. To do so, place book.php directly into .openshift/cron/minutely, make it executable, and add this shebang to it:
#!/usr/bin/env php
Hope this helps.
I use openshift aswell and executed a php file with a cron aswell.
#!/bin/bash
php ${OPENSHIFT_REPO_DIR}index.php
This executes the script normally at first sight. However no output was produced. The problem was, that all the required php files couldnt be loaded because the working directory was not the same as it would be when loaded by the webserver. Setting the working directoy in the php script itself will prevent this error and makes the script perfectly executable by the cron.
This should help some people to get their script running.
I need your help here.
I wrote one PERL script for PHP application which needs to be run for every 5 mins.
This script will call PHP program, which will fetch data from MySQL DB and will generate a excel report and will mail those reports to specific users.
Every thing seems to be fine when I ran this script manually with the command (perl reports.pl).
But when I set this Perl in a cron tab, nothing works and reports are not getting generated.
Details: perl script path /opt/app/deweb/web/EDI/Microsoft/reports.pl
this script will call PHP program (/opt/app/deweb/web/EDI/Microsoft/reports.php)
content of script
#!/usr/local/bin/perl
use Net::FTP;
use File::Copy;
use POSIX;
#errorreport = `php /opt/app/deweb/web/EDI/Microsoft/reports.php`;
print "#errorreport\n";
exit;
It is working perfectly when running Manually using command - perl reports.pl
No results, when set in CRON:
*/5 7-19 * * * /usr/local/bin/perl /opt/app/deweb/web/EDI/Microsoft/reports.pl
Please note that this crontab is under super user account named webserv and my login is having access to edit under this super user account.
I'm editing this cron tab using command :: sudo -u webserv crontab -e
I would check the following:
Does it run using sudo -u webserv perl reports.pl? If not, fix the problem for the webserv user (permissions or whatever) and it should work via cron too.
Does which perl using your login give you /usr/local/bin/perl? If not, change the path to Perl in crontab to what you got in which perl to fix the problem.
I found myself to be in the same situtation. After trying to find out the reason, I am almost sure about the reason this happens. Crontab does not have the same environment variables as you when running the script. You must be sure about paths. Try for example run your script like /perl-path /path-to-perl-script/script.pl outside the parent directory of the script and I am almost sure that your programm will not find some files. And as you call one php script from the perl script, it's possible to have the same problem with paths to your php script too.
So the solution is to use absolute paths and no relative.
Also at your perl script don't use php but /full-path-to-php for example:
#errorreport = /usr/bin/php /opt/app/deweb/web/EDI/Microsoft/reports.php;
I have a php webpage located on Webserver1, which is from Host1.
I also have a bash script located in Gameserver1 which is from Host2.
Is there any way to send a command from Webserver1 to Gameserver1 to execute the bash file? The webpage and file are on different VPSs. Both are running Debian 7.
The script is literally one line, to execute a java command via a screen, so the server can start if a player notices it's down. The command's available already so it doesn't need to be a secure way of hiding what the command is.
There are 2 ways I can think of. either create a bash file in Webserver1 that connects through ssh and executes the bash script you need on Gameserver1. then run it through php with exec() command.
Or you can create a php file in Gameserver1 that uses exec() to execute the bash script you need on Gameserver1 and call it using file_get_contents() on Webserver1, which is not that secure since anyone can call that file and run your script.
I would like to be able to either launch php in interactive mode via phing or via PHP (worst case scenario, phing can run an adhoc task with the desired code).
I've gotten this far:
<?php
$cmd = 'php -d auto_prepend_file=bootstrap.php -a';
passthru($cmd)
And the above almost gets me what I want. I enter a shell I can interact with, but the prompts are gone (the php > at the start of each line), all meta-commands (e.g., \>) totally fail, and typing exit; does nothing instead of exit the shell. So, as you can see, this isn't the ideal shell. Is this even possible without installing phpsh?
Thanks in advance.
I think PsySH will give you want you want. It's a PHP REPL that gives you the option to configure it to automatically include a bootstrap file.
I have a windows server, and I' trying to use scheduled tasks. When I create the job and try to run it through the interface, it says it works, but when I look at the DB it shows me that nothing happend. This is what I placed in the Path to executable file
"D:\Parallels\Plesk\Additional\PleskPHP5\php.exe" -f "D:\inetpub\vhosts\fab-offers.com\httpdocs\cms-sites\vipstore\users\index.php"
Check for:
Is the script working if you run it manualy?
Does php error logs contain anything related to the script?
Does the script contain paths like $_SERVER['DOCUMENT_ROOT'] that it won't have when run not from browser?