Archive

Posts Tagged ‘cron’

php-cron – schedule jobs to run by the second and more

January 6th, 2011 No comments

Yet another challenge, mostly like all other developers, ours at Saturn too believed that scheduled jobs could be run to the lowest frequency at every minute. This stands true if the job is handled only by *nix cron or by windows scheduler. For even further control one should write a Sleep-And-Run. I used to do this in shell script for most of my requirements. Just the other day some one challenged me to get done with one similar in php.

The outcome is a crude one, ServiceManager, which runs based on a configuration file and its run frequency. Best not to change the frequency or your configuration would never support anything less than the frequency as well as will only support multiples of the frequency. The configuration file is the famous ini file format with item names in square brackets, with configuration on two lines. The sample attached ServiceManager.ini should give an idea.
Read more…

Categories: PHP Tags: , ,

MySQL: Optimize all tables; Run using cron

June 17th, 2010 No comments

I was looking for a optimize table script and finally stumbled upon some code which could be salvaged into a shell script. The full code is reproduced here for future reference.


#!/bin/bash
 
#-- I usually add the root username and password to the ~/.my.cnf
MYSQL_CMD='/usr/bin/mysql '
 
$MYSQL_CMD -e "SELECT concat('OPTIMIZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,';') as cmd FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 10 AND NOT ENGINE='MEMORY' INTO OUTFILE '/tmp/cmd.sql'"
 
$MYSQL_CMD < /tmp/cmd.sql
rm -f /tmp/cmd.sql

Categories: Linux Shell, mysql Tags: , ,

Needed a random timed cron; Got it

August 18th, 2009 1 comment

Sorry this is nothing related to php, though I wanted to run a cron job or scheduled job at a random time, searching the Internet gave me lots of ideas but I found the apt solution only yesterday.
Read more…

Categories: Tips, Uncategorized Tags: ,