Securely specify mysql credentials in automated scripts

by admin

Often, you may want to run a script that uses a username and password to access data in a MySQL database. Securely running a script like this manually is easy – simply use the ‘-p’ option for the MySQL client, and it will prompt you for the password. However, this is not an option if you want to automate the script.

There are several ways to provide the password in a way that can be used with automated scripts, but only one that is both flexible and secure. You can specify the password on the command line itself (with ‘mysql -p ‘); however, this allows the password be seen by other users who run commands like ‘ps’. Another option is setting the environment variable “MYSQL_PWD” to the password, but this can also be seen by other users. Read the rest of this entry »

Using the Data::Dumper module to debug your Perl scripts

by admin

If you’re ever writing a Perl script that contains fairly complicated data structures (multi-dimensional arrays, hashes of arrays, etc), or you’re debugging code that contains complicated objects, it may be helpful to view the current state of those data structures in their entirety.

This is easy to do with Data::Dumper. Although the features the module provides are fairly complex, it’s easy to use it to just print out the contents of something. Do do this, you’ll first need to import the module with ‘use Data::Dumper;’. Then, to dump the data in an array(for example), simply do ‘print Dumper(@array)’. Read the rest of this entry »

Easily installing Perl modules with Yum

by admin

Although many Perl modules are available through Red Hat and CentOS’s repositories, the name the modules have in the repository differ from the name of the module itself.

To use yum to install a Perl module using the module name, just place ‘”perl()”‘ around the name of the module (double quotes included) when giving it as an argument to yum. For example, to install the ‘Net::Telnet’ module, you would run ‘yum install “perl(Net::Telnet)”‘.

Alternatively, to construct the correct package name, you would prepend the module’s name with ‘perl-’, and change all of the instances of ‘::’ to ‘-’. For example, the package for the ‘Net::Telnet’ module would be ‘perl-Net-Telnet’.

Finding space hogs

by Michael Klatsky

I know this is a common post out there, as a google search will bring this up multiple times, but here it is anyway. A great alias to set up on your system to aid in finding space hogs in a given filesystem or directory is as follows:

alias ducks=’du -cks * |sort -rn |head -11′

Add the aliases to whichever file you keep them in (.bashrc, .aliases, etc)  and then run ‘ducks’ for output similar to this: Read the rest of this entry »