script

A Perl script to print Nagios log records in a human readable date format

Perl date FAQ: Can you share a Perl date example where you print a date in a decent human-readable format?

Update: Be sure to look at the comments below for some great Perl "one liners", i.e., one-line solutions to this problem.

In this blog I'll share the source code for a Perl program that takes nagios.logrecords as input, then outputs the records with a human-readable date format. More specifically, the input records look like this:

Reading Scala command line arguments

Scala command line FAQ: How do I read command line arguments (args) in a Scala shell script?

If your Scala shell script is very short, and you're not using an object or class declaration -- i.e., you have no main method -- you can access the script's command line arguments through the default args array, which is made available to you by Scala.

For instance, you can create a one-line Scala script named hello.scala like this:

Ruby command line arguments

Ruby FAQ: How do I read command line arguments in a Ruby script (Ruby command line args)?

To read command line args in a Ruby script, use the special Ruby array ARGV to get the information you need. Here are a few examples.

1) Getting the number of command line args

To get the number of command line arguments passed in to your Ruby script, check ARGV.length, like this:

Handling spaces in Linux shell script input (and for loops)

Linux shell script FAQ: How can I deal with spaces (blank spaces) in my input data when I'm writing a shell script for loop or while loop?

I was just working on a Linux shell script, and ran into the ages-old problem of handling data that has spaces (space characters) in it. I run into this any time I try to read a data file with blank spaces in it, or when I run into files and directories with spaces in their names. Whenever I try to work this data like this in a shell script for loop, the spaces always ruin what I'm trying to accomplish.

A MySQL database backup (mysqldump) shell script

MySQL database backup FAQ: Can you share a Linux shell script that I can use to make a MySQL backup (i.e., a shell script that wraps the mysqldump command)?

I currently have a collection of websites on several different servers (including GoDaddy and A2 Hosting web servers), so I was just spending some time trying to automate my MySQL database backups. To that end, I just created a MySQL shell script that I use on each Linux server to make my database backups, and I thought I'd share that script here.

PHP ping script examples

While working on a shared hosting server, I found that the company I'm working with has disabled my access to the Unix/Linux ping command. Not to be deterred, I found several different ways to run a ping command with a PHP script.

Use the Net_Ping module

The first thing you can try to do is use the PHP PEAR Net_Ping module to get around this problem. In short, you install it like this:

pear install Net_Ping

Then use it like this:

Syndicate content