THE LATEST

Shhhh! Keep quiet cakephp console

Its been a while since I've had a chance and/or motivation to write any notes down, in the words of Willie Wonka "So much time, so little to do....ahhhh, strike that, reverse it..."

At any rate this note is in relation to the cakePHP console and keeping it quiet. Sometimes you need the verbose / debug information and other times it makes it impossible to work in the same shell window.

Sure from a cron perspective you can direct everything to the void (/dev/null) but other times its not possible. For example when you have an application executable that regularly calls a cakephp shell script to update data to your mysql database. Say you start this application from your shell session and you start doing other work, then blamb you get bombarded with console output. Sure you could have installed the mysql libraries and written the code to directly enter the data but by running it through cakephp's console you can make use if the validation code you have already written.

I found teknoid had an article about keeping your console silent which worked for the most part but still output a couple of linefeeds.

I tracked the offending lines down to other parts of cake 1.2.x libraries but after considering changing those files I decided the best solution for me was to add a -quiet option to the cake console so you could easily switch between testing your code in verbose mode else keep it quiet by simply adding the command line -q script argument.

The cake/console/cake script code was changed as follows :-

Show Plain Text
Bash code
  1. LIB=${0/%cake/}
  2. APP=`pwd`
  3. while getopts ":q" opt; do
  4.   case $opt in
  5.     q)
  6.       quiet=1;
  7.       shift $((OPTIND-1));
  8.       OPTIND=1;
  9.   esac
  10. done
  11. if [ $quiet != 1 ]; then
  12.   clear
  13.   exec php -q ${LIB}cake.php -working "${APP}" "$@"
  14. else
  15.   exec php -q ${LIB}cake.php -working "${APP}" "$@" >/dev/null 2>&1
  16. fi
  17. exit;

You can run the cake script in quiet mode as follows :-

Show Plain Text
Text code
  1. cake -q -app <path> <cake console script>

The code simply consumes the -q argument passed to the cake console script and then runs the script in either the quiet or verbose mode.

Filed under: Cakephp  Tags: Shell

RECENT ARTICLES

Linux disk usage statistics

The following are some useful commands to figure out which directory is consuming all of your disk space...

Filed under: Linux  Tags: Debian, Ubuntu

Displaying your cakephp 1.2 version

The CakePHP dev's have made it super simple to display your cakephp version, I have only just stumbled across it when looking for something else in the API. Like me you might not have spotted it, its not an essential bit of code but a nice to have for those administering many sites on various servers and much better than finding the version text file on each install. I display the version number in the system setup part of the sites admin dashboard along with other framework related settings...

Filed under: Cakephp  

How to reboot a locked up local or remote Linux box

On the odd occasion your Linux box will lock up and won't appear to be working, at this point you go darn I'd love to do a controlled shutdown, here's one way of rebooting your local or remote Linux box...

Filed under: Linux  Tags: Debian, Ubuntu

Command to list only directory names under Linux

Sometimes you need to only only list the directory names under Linux, a simple command for this is...

Filed under: Linux  Tags: Debian, Ubuntu

How to setup a 30 second Cron job

Sometimes you need a cron job at a frequency less than the minimum of 1 minute (60 seconds) that cron allows. One way of achieving this is by...

Filed under: Linux  Tags: Debian, Ubuntu