I have created a shell script as follows
<?php
class EmailShell extends AppShell
{
public function main()
{
$this->out('Hello world.');
}
}
When i navigate to the Console folder in command line and type cake email i get the following error.
Error: Shell class EmailShell could not be found.
#0 C:\wamp\www\gitgrow\lib\Cake\Console\ShellDispatcher.php(167): ShellDispatche
r->_getShell('email')
#1 C:\wamp\www\gitgrow\lib\Cake\Console\ShellDispatcher.php(69): ShellDispatcher
->dispatch()
#2 C:\wamp\www\gitgrow\app\Console\cake.php(33): ShellDispatcher::run(Array)
#3 {main}
create a shell for use in the Console. For this example, we’ll create a simple Hello world shell. In you applications Console/Command directory create EmailShell.php. Put the following code inside it:
class EmailShell extends AppShell {
public function main() {
$this->out('Hello world.');
}
}
Then run this command :
Console/cake email
or
cake email
Run it at C:\wamp\www\gitgrow\app\. It should work.
cd C:\wamp\www\gitgrow\app
Console\cake email
If your shell class is in the right place, then it might be a problem that cake does not know where your app root is. You can specify this using the -app argument.
cake -app ../app email
See the following link about how to run Cake shells in cron:
http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html
Your cron command basically calls cd into the app directory and the cake command to run the shell together.
Related
I wrote a ruby class which has print statement. Then i wrote a Groovy class which invokes this ruby class and executes
I tried like Process.execute("ruby.exe test.rb")
Ruby code-->
class Test
puts "hello, I am ruby"
end
Groovy code-->
class TestGroovy {
static main(String[] args) {
Process.execute("ruby.exe test.rb")
}
}
i need to get output as hello, I am ruby when i run TestGroovy.
From the docs:
Groovy provides a simple way to execute command line processes. Simply write the command line as a string and call the execute() method. E.g., on a *nix machine (or a windows machine with appropriate *nix commands installed), you can execute this:
def process = "ls -l".execute() // <1>
println "Found text ${process.text}" // <2>
executes the ls command in an external process
consume the output of the command and retrieve the tex
You can execute Ruby code from Groovy or Java code using a JSR-223 script engine. Here is an example Groovy script:
#Grab('org.jruby:jruby:9.2.5.0')
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
ScriptEngine engine = new ScriptEngineManager().getEngineByName('jruby')
engine.eval('puts "Hello world!"')
eval() also accepts a java.io.Reader which you could get from your file path. There are lots more details on ways to run Ruby from Java/Groovy here: https://github.com/jruby/jruby/wiki/RedBridge
i'm a newbie in using codeigniter cli
i'm using xampp and my project located in
c:\xampp\htdocs\mycli\
my code is like this
public function myfunction($to = "WORLD"){
echo "HELLO {$to}!".PHP_EOL;
}
i trying to use this cmd line base on codeigniter tutorial on cli
c:\xampp\htdocs\my_cli\index.php mycontroller myfunction "test"
but it doesn't work it just showing index.php file. i also using htacess to remove the index.php in the url.
try the following code
cd /path/to/project
php index.php mycontroller myfunction test
Either you can execute php index.php controller action
or you can call it thorough the http protocol
wget http://example.com/example/test/bar/
curl http://example.com/example/test/bar/
Reference: http://mildcoder.com/handling-codeigniter-in-cli-and-cron-jobs/
step1: cmd
step2: check your cmd ->
"php -V"
if step2 got error: your php.exe is not in your sys's path{
step3:
c:\xampp\php\php c:\xampp\htdocs\my_cli\index.php mycontroller myfunction "test"
}
if step2 show like this: php 5.3.6 ...............{
step3 is:
php c:\xampp\htdocs\my_cli\index.php mycontroller myfunction "test"
}
Ok I looked at every other thread and have done exactly what they've done and what it says in the manual and I can NOT figure this out for the life of me.
The results of the cron job are being emailed to one of my emails. ALL it is doing is printing out the html markup of the layout... And printing the base page content... It's like it's not registering anything.
php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats
That's my command line.. I tried replacing php with the user/local/bin/php thing as well and it didn't work. The thing is is that I have other cron jobs running off procedural PHP code that work FINE with php path/to/cron.php... But it won't work with CI..
My controller is Cron and my method is decrease_pets_stats..
//decrease pets stats
public function decrease_pets_stats() {
$this->load->model('Cron_model', 'cron');
$this->cron->decrease_pets_stats();
echo 'Decreased pet stats';
}
And here is the logic of the method:
//decrease pets stats
//runs every hour
public function decrease_pets_stats() {
$this->db->set('hunger', 'hunger - 5');
$this->db->set('happiness', 'happiness - 5');
$this->db->set('loyalty', 'loyalty - 5');
$this->db->update('user_creature');
}
Does anyone have any idea why it's just printing the layout markup? My constructor looks like this:
public function __construct() {
parent::__construct();
if( ! $this->input->is_cli_request()) show_error('Direct access is not allowed');
$this->load->model('Cron_model', 'cron');
}
And my parent constructor holds quite a bit of stuff (loading helpers and libraries along with getting the user information to appear on each page if they are logged in.
Does it matter if this is at the top of the controller before even opening the controller Cron class?
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
The default PHP install you are using was probably compiled as CGI-FCGI, not for CLI. It depends on your host and/or server, but you'll need to search for your PHP install for the command line interface, and then use that in your cron job. I had the exact same problem on Hostmonster, and my cron command ended up being:
/ramdisk/bin/php5-cli ~/public_html/sitefolder/index.php controller method
For me, the PHP I needed was in /ramdisk/bin/php5-cli.
For CodeIgniter 2.2.0
You can try this two method:
php-cli /home/username/public_html/index.php controller method
wget http://www.example.com/controller/method
or at your case
php-cli /home/username/public_html/index.php Cron decrease_pets_stats
wget http://www.example.com/Cron/decrease_pets_stats
It works fine with me..
Cheers!
Had the same issue and after trying whatever I could thing the obvious worked...
/usr/local/bin/php /absolute/path/to/index.php cron
/usr/local/bin/php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats
This fixed it.
Here is solution first you need to find path from phpinfo document_root file name
php5 /home/abc/public_html/index.php folder_name controller function
I am trying to work out how to setup a Shell to run as a cron, I have created a TaskEmailerShell.php file at /app/Console/Command/TaskEmailerShell.php with the following code:
App::uses('CakeEmail', 'Network/Email');
class TaskEmailerShell extends AppShell {
public $uses = array('Task');
public function main()
{
// GENERATE AND SEND THE EMAIL
// ------------------------------------------------------------>
$email = new CakeEmail();
etc etc
I have followed the instructions here and when the cron runs I get this error:
/home/village/public_html/app/Console/cakeshell: line 14: cake: command not found
My cron command is:
/home/village/public_html/app/Console/cakeshell TaskEmailer -cli /usr/bin -console /Cake/Console -app /home/village/public_html/app >> /home/village/public_html/emailer_log.log
Any suggestions where I am going wrong?
The cakeshell script you're referring to there requires the cake console binary to be somewhere in PATH, or (at least from looking at the usage example), for you to have specified the full path to the Console with the -console argument. It looks like you've got a relative path there.
Personally I recommend just calling the cake console directly from your cron job. As other needs arise you may end up writing a script like cakeshell to wrap the console. You could try something like :
# m h dom mon dow command
*/5 * * * * /home/village/public_html/lib/Cake/Console/cake -app '/home/village/public_html/app/' TaskEmailer >> /home/village/public_html/emailer_log.log
Command not found usually means your PATH is the problem. Programs run from cron might not even have PATH set. Any script started by cron must set PATH near the beginning or it won't find any of the programs it is supposed to run.
The error occurs at line 14 in the file cakeshell: $cmd. cmd is set at line 4.
#!/bin/bash
TERM=dumb
export TERM
cmd="/opt/lampp/htdocs/MyApp/app/Console/cake"
while [ $# -ne 0 ]; do
if [ "$1" = "-cli" ] || [ "$1" = "-console" ]; then
PATH=$PATH:$2
shift
else
cmd="${cmd} $1"
fi
shift
done
$cmd
Originally line 4 is
cmd="cake"
Change it to absolute path like:
cmd="/opt/lampp/htdocs/MyApp/app/Console/cake"
where MyApp is the application directory. I have faced this problem even after PATH settings. Then mentioning the absolute path solved it.
I am a newer to cakephp .I config the cakephp shell as the cakephp
handbook says,when I run the HelloShell with the command cake
Hello ,I got the error information as follows:
Error: Shell class HelloShell could not be found.
1#G:\htdocs\cakedemo\lib\Cake\Console\ShellDispatcher.php(191):ShellDispatcher>_getShell('hello')
2#G:\htdocs\cakedemo\lib\Cake\Console\ShellDispatcher.php(69):ShellDispatcher->dispatch()
3#G:\htdocs\cakedemo\app\Console\cake.php(33):ShellDispatcher::run(Array) {main}
my cakephp version :
Welcome to CakePHP v2.2.0-beta Console
App : Console
Path: G:\htdocs\cakedemo\app\Console\
anyone who is helpful can give me a advice,plea.
there is your mistake.
you should always be in your APP path to execute the cake console.
...app/>../lib/Cake/Console/cake MyShell
or (using the APP Console folder):
...app/>Console/cake MyShell
and MyShell should then be in ...app/Console/Command/.
Thats all there is to it.
Error: Shell class HelloShell could not be found appear because: typo mistake or run command at wrong directory.
Solution:
1. Setup path for php.exe, cake.exe
2. For example, my Cake website root is:
C:\tools\xampp1.8.3\htdocs\cakephp-2.5.5
Create new file in folder C:\tools\xampp1.8.3\htdocs\cakephp-2.5.5\app\Console\Command\HelloShell.php with content:
class HelloShell extends AppShell {
public function main() {
$this->out('Hello world.');
}
}
3. Open cmd, type:
cd /d C:\tools\xampp1.8.3\htdocs\cakephp-2.5.5\app
cake hello
We use hello in command line to call HelloShell class, because "Convention over configuration".
Reference:
http://book.cakephp.org/2.0/en/console-and-shells.html#creating-a-shell
Make sure you give cake folder path in /var/www/html/Console/cake.php
ini_set('include_path', $root . PATH_SEPARATOR . 'Cake' . $ds . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
Then go to root folder. In my case the location will be
/var/www/html/
then give the shell file name; hello is my shell name, that would be
/var/www/html/Console/cake hello
combining together
/var/www/html$ /var/www/html/Console/cake hello
Your shell will be executed.