Skip to main content

Commands

Debug you PHP code using DRUSH

Submitted by sunildhimal on
Drush is a very handy tool which makes development in Drupal very fast and easy. Almost everyting is JACA("just a command away"). This particualr tip will help you to evaluate your php code using Drush. Examples: Consider a function: ji_custom($node). To evaluate/debug this function I type following in Drush: drush php-eval "ji_custom($node);"
Aliases for php-eval are: eval, ev N.B: JACA is invented while writing this post :)

Batch Process Images in Linux

Submitted by amitsedai on
Sometimes its a pain when you want to modify, resize multiple files at once in Linux. Fortunately ImageMagick comes with a handy command called convert that makes the work simpler Install ImageMagick in Ubuntu
sudo apt-get install imagemagick
Batch Process set of files in a folder and resize them to 1024X768
for file in *.jpg; do convert "$file" -resize 1024x768 "$file"; done
You may also try an app called as phatch for GUI related batch processing of images. Snippet to bulk rename files by replacing strings in filename

Clear Sendmail Queue

Submitted by system on
To clear the sendmail queue, one can manually delete the contents of the folder: /var/spool/mqueue. To see the contents of the queue,one can type the command.
mailq
-- Source: http://www.cyberciti.biz/faq/linux-unix-bsd-clear-sendmail-queue/

Update File Path in Drupal

Submitted by amitsedai on
We have a site that we had been migrating since Drupal 4. Few days back when we tried to migrate the same from Drupal 6 to Drupal 7. There was an issue with respect to file location that was present since previous upgrades. To resolve that a symlink was created called "files" with linked to sites/default/files during D6 upgrade. This led to first loss of many files as Drupal does not handle symlink based file saving well. Secondly the files created were saved under public://files/filename.ext instead of public:://filename.ext which caused created files not being accessible.

Executing PHP in command line

Submitted by amitsedai on
There are times when one needs to execute PHP in command like, for example trying the date command output or a one line execution. For trivial tasks, executing the same at the command line without the need for writing and executing at a file level is a great tool for time saving. The argument to be used is : -r Example: php -r '
$a = range(0,2);
foreach($a as $b) {
echo "entry: $b\n";
}
'
The output is:
entry: 0
entry: 1
entry: 2

Another example:
php -r '
> echo date("d-m-Y");
> echo "\n";
> '
14-01-2013

RSync file transfer on a different port

Submitted by amitsedai on
To transfer file to a different port using RSync: rsync -avz --progress --rsh='ssh -p1516' source user@host:destDir/
rsync -avz -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /local/path/
The source can be a file or a directory to be copied to the destination directory --source: http://www.linuxquestions.org/questions/linux-software-2/rsync-ssh-on-different-port-448112/ http://mike-hostetler.com/blog/2007/12/08/rsync-non-standard-ssh-port/

Understanding Server Bottlenecks

Submitted by amitsedai on
If the server becomes slow or unresponsive, execute the top command. The first thing to look is the load average. The load average typically looks like this: load average: 0.49, 0.41, 0.35 . The first number represents the server load average currently, the 2nd number for load average 5 minutes ago and 3rd number for 15 minutes ago. if you have 1 CPU and the load average is 1, it means that the server has been busy constantly. Four 4 core machine if the average is 4, then all cores are busy.