Hi I have set in my cpanel a cron job that runs every minute:
/usr/bin/php /home/mysite/public_html/index.php --uri="cron/test"
the cron above is going through my index.php because i'm logging it if it works although it doesn't go on my cron controller "cron/test"
in my index.php i am doing this for test purpose only and i am getting indexcalled.txt:
$fp = fopen('indexcalled.txt', 'a+');
fwrite($fp, "POST: " . serialize($_POST));
fwrite($fp, '-----------');
fwrite($fp, "GET:" . serialize($_GET) . "\r\n");
fclose($fp);
and in my Cron controller i have this, but im not getting crontest.txt
public function action_test() {
$fp = fopen('crontest.txt', 'w+');
fwrite($fp, date("Y-m-d H:i:s") . "cron test initiating...\n\n");
fclose($fp);
}
Is there anything I am not doing right or I might have forgotten to set?
Have you tried curl command in cron job ?
Related
So I'm using node-cron module.
I'm using this simple code and it should print go! everyday at 14:17.
I'm running the code in my local machine, everythings going well. But then I try to run the code on my server in DigitalOcean (Ubuntu 14), it never prints go! at 14:17. Nothing happen. Can you tell me what I've been missing?
var cron = require('node-cron');
var task = cron.schedule('0 17 14 * 1-12 0-7', function() {
console.log('go!');
}, false);
task.start();
Oh, by the way I tried running another code on my server and it works, print go! at 0 second
var cron = require('node-cron');
var task = cron.schedule('0 * * * 1-12 0-7', function() {
console.log('go!');
}, false);
task.start();
Check your server timezone and your local timezone and see if they match.
Reconfigure your server timezone with sudo dpkg-reconfigure tzdata
i want to run a ajax function in cronjob..
my code is :
<?php
function sendSMS($username, $password, $phones, $text){?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
var smsUrl='http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=<?php echo $username ?>&password=<?php echo $password ?>&sendername=NETSMS&mobileno=<?php echo $phones ?>&message=<?php echo $text?>';
$.ajax({
data : '',
type : "get",
url : smsUrl,
error : function(resp){
},
success : function(resp){
}
});
});
</script>
<?php }?>
the code is working fine if i run the php page manually in the browser.. but not work in cron job... is it possible to run ajax function in cronjob?
Not possible to my attention (or just very difficult and not user-friendly).
You can acquire the same thing using CURL.
Make your cron job run a script that contacts bulksms.mysms... through CURL.
I dont know if your server runs asp or php or whatever.
Example:
$ch = curl_init();
$remote_url = 'http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=' . $username . '&password=' . $password . '&sendername=NETSMS&mobileno=' . $phones . '&message=' . $text;
curl_setopt($ch, CURLOPT_URL, $remote_url);
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Return output
$output = curl_exec($ch);
Are you sure you installed curl library for php on your server?
I'm trying to learn now technology - reactPHP. But I'm stacked with starting script. I'd edited it little bit, but I have problem, if I call the react loop, the script is done twice.
I have this code:
<?php
require 'vendor/autoload.php';
$app = function ($request, $response) {
$date = new DateTime();
file_put_contents("data.txt", $date->getTimestamp().";", FILE_APPEND);
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end("Done\n");
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run();
and if I call http://localhost:1337/react/index.php I get in data.txt this
1439849018;1439849018;
I'm expecting only one value.
I have tested your code and the problem is because your'e testing it in your browser. Your browser send request and then ask for favicon. That's it. On the image from Inspect it's the first and third line. Next time try to run the scripts from cmd.
I am trying to execute a child process in a different directory then the one of its parent.
var script = "drush language-add cn";
var folderDrush = "/data/www/sites/site_cn_country";
exec(script, {cwd:folderDrush} , function (err, stdout, stderr) {
if(err) {
sendErr("drush", stderr);
sendCommand(script);
sendCheck("drush", false);
}
});
This script returns:
The drush command 'language-add cs' could not be found. Run drush [31;40m[1m[error][0m cache-clear drush to clear the commandfile cache if you have installed new extensions.
But when I execute manualy, drush language-add work fine.
I test there commands too :
pwd : /data/www/sites/site_cn_country
id -u -n : root
ll : Command not found (why ? manually work...)
echo $SHELL : /bin/bash
This is not a direct answer, but you could change path before running the command:
var script = "cd /data/www/sites/site_cn_country && drush language-add cn";
I've been unable to properly setup Hubot and node-cron to execute tasks within my IRC channels.
This page shows how I initially setup my code:
https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-periodic-task-execution
Here is the link to node-cron:
https://github.com/ncb000gt/node-cron
I'm thinking I'm running into an issue with Hubot's IRC adapter, but I'm not sure. Any advice and code examples would be welcome.
Here is where I've ended up in testing:
module.exports = (robot) ->
cronJob = require('cron').CronJob
tz = 'America/Minneapolis'
new cronJob('30 * * * * *', testFunction, true, tz)
room = '#support' #not used in this case
testFunction = ->
robot.send "I work!"
or per example from Leanpub
testFunction = ->
robot.messageRoom room "I work!"
cron jobs setup after Hubot is running work fine:
Hubot new job "<crontab format>" <message> - Schedule a cron job to say something
Thank you again, all!
So we ended up using a slightly different format to get this up and running. For our uses, we excluded the time zone info, but it works with it as well.
module.exports = (robot) ->
cronJob = require('cron').CronJob
new cronJob('0 */1 * * * *', everyMinute(robot), null, true)
everyMinute = (robot) ->
-> robot.messageRoom '#billing', 'hey brah!'
If anyone has this running with code closer to the examples, feel free to answer.