unix

Searching Drupal Files with Ack

Ack is a recursive grep-replacement Perl script that you can download from: http://betterthangrep.com It is somewhat similar to "egrep", but is much smarter and has ten times nicer output format. It also automatically ignores annoying .svn files and you can teach it different file types.

If you are a Drupal developer you need to put the following line in your /etc/profile:

export ACK_OPTIONS=--type-set=php=.php,.module,.inc,.install

After which you can enjoy yourself some:

ack --php "check_plain"

Unix Shell Programming and Broken Symlinks

The well-known approach for checking whether path exists, in Unix, is: "if [ -e $path ]" condition. However, contrary to popular belief, "-e" does not always work. The "-e" check works for folders, files etc with one exception: if there's a broken symlink on the path, it won't recognize that. Which makes sense: broken symlink is not a valid path. However, if you are writing some kind of cleanup code, you do want to be able to check on broken links, as well. To achieve that, you need to add extra condition:

if [[ -e $filepath ||  -L $filepath ]]; then
  echo "There's something at: $filepath"
fi

Replace a Function Name in Drupal Source Files

> perl -i -pe 's/oldname_/newname_/g' `find | grep "\.module$"`

Or if you want to first check the results:

> perl -pi.bak -e 's/oldname_/newname_/g' `find | grep "\.module$"`

which will create backup of original files. Those you can delete later with:

> find . -name "*.bak" -exec rm -rf {} \;

You can replace ".module" with ".inc" or "tpl\.php" if you also need those processed

Chrooted FTP Access

FTP is an insecure, outdated and overall horrible protocol that you should never use yourself. Yet, sometimes you want to allow some people to upload files to your server, but you don't want them poking around your server or users demand FTP because they are used to it and have no idea what SSH/SFTP is.

Either way, following is how you "chroot" ftp users to their home folder, so they can't do any harm:

  • Download latest proftpd source to /usr/local/sources and change to that folder.
  • ./configure --sysconfdir=/etc --localstatedir=/var
  • make
  • make install
  • Edit vi /etc/proftpd.conf:
    • Change "Umask 022" to "Umask 002" #So, files they upload are group-writable
    • Uncomment "DefaultRoot ~" # this does actual chrooting
  • Make sure "/bin/false" is listed among the shells in "/etc/shells"
  • Create new unix user with "-s /bin/false"
  • Start proftpd daemon

Line Delimiters in Eclipse

Eclipse is an IDE of choice for many. It's been very popular among Java developers for a long time, but lately it is getting some traction in the PHP world, as well. A big contributor has been the absolutely fabulous Eclipse PDT project that makes Eclipse PHP-intelligent.

Whether you are developing in Java, PHP or any other language Eclipse supports, you most probably have to deal with cross-platform issues. One of the most trivial, yet annoying is the matter of line-delimiters. For whatever historical reasons Windows, Unix/Linux and Macintosh use different delimiters. It almost makes you wonder if the creators of the three major operating systems were sadistic enough to intentionally employ all three possible variations to make our lives more difficult.

Scheduling Skype Phone Call - Geek's VoIP

On unix-compatible systems, you can schedule Skype to make phone calls. For instance, On OS X, you can do it with a simple crontab setup, like:

55 7 * * * open callto://+13056740165 > /tmp/skype.log

which will call certain unfriendly company's customer service number, every day at 7:55 AM.

Syndicate content