Bash

How to find your Ubuntu version (command line)

To determine your version of Ubuntu from the command line type:

cat /etc/lsb-release

And you should see something like this in response:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"

Automated MySQL Backups

The HOWTO will show how to automate the backup of your local MySQL server on a daily basis. The backup process uses a bash script and the local logrotate functionality to achieve an automated systems. The backup is processed daily via cron (see /etc/cron.daily/logrotate).

While this HOWTO is written for a local development environment it could easily by modified for remote multi-server environments.

Step1: Create the backup script

Create a file at /usr/local/sbin/backup_mysql.sh using your favorite text editor. I use joe:

Generate Random Numbers with Bash Scripting

To generate random numbers with bash use the $RANDOM internal Bash function. Note that $RANDOM should not be used to generate an encryption key. $RANDOM is generated by using your current process ID (PID) and the current time/date as defined by the number of seconds elapsed since 1970. The range of returned values is 0 to 32767.

This will return a number between 1 and 100:

NUMBER=$[ ( $RANDOM % 100 )  + 1 ]

Here is a function to dynamically imitate a die:

#!/bin/bash
#
# Simple script to generate a random number
#
# written by Dallas Vogels
Syndicate content