Thursday, 21 June 2012

Bash Script: Find and replace string within string

Below is a simple bash script which will find and replace the substring withing the string. Feel free to use or modify this script.

Source: cat stringreplace.sh
#!/bin/bash

echo -n "Enter main string: "
read string

echo -n "Enter the sub-string that you want to replace: "
read old

echo -n "Enter new sub-string that you want to replace with: "
read new

echo "The new string is now: ${string/$old/$new}"

Result: ./stringreplace.sh 
Enter main string: linuxpoison
Enter the sub-string that you want to replace: poison
Enter new sub-string that you want to replace with: os
The new string is now: linuxos

Tuesday, 12 June 2012

Bash Script: Array examples and Operations

Below is a simple script which demonstrate all the different kind of array operations like ...

 * Display arrays elements
 * Iterate through the array elements
 * Add a new element to array
 * Replace an array element
 * Copy array
 * Delete array

Source: cat array.sh
#!/bin/bash

array=(a b c d)

# Get the lengthe of array
LEN=${#array[*]}
echo "Length of the array is: $LEN"

# Print the array elements"
echo "${array[@]}"
echo "----------------------------------"

# Iterate through the array
for ((i=0;i<${#array[*]};i++)); do
    echo "$i : ${array[$i]}"
done
echo "---------------------------------"

# Add new value to the end of the array
array=("${array[@]}" "e")
array[10]="f"   # Add another element at index 10
echo "${array[@]}"
echo "---------------------------------"

# Copy the array to another array
declare -a newarray
for i in ${array[@]}; do
    newarray[${#newarray[*]}]=$i
done
echo "New array values: ${newarray[@]}"
echo "----------------------------------"

# Remove a element from the array
unset array[2]
echo "${array[@]}"
echo "---------------------------------"

# Replace a array element
array[0]="z"
echo "${array[@]}"
echo "---------------------------------"

# Delete entire array
unset array
echo "${array[@]}"

Continue Reading...

Thursday, 7 June 2012

Setting up GlusterFS Network Storage under Ubuntu

GlusterFS is an open source, distributed file system capable of scaling to several petabytes (actually, 72 brontobytes!) and handling thousands of clients. GlusterFS clusters together storage building blocks over Infiniband RDMA or TCP/IP interconnect, aggregating disk and memory resources and managing data in a single global namespace. GlusterFS is based on a stack-able user space design and can deliver exceptional performance for diverse workloads.

GlusterFS supports standard clients running standard applications over any standard IP network. No longer are users locked into costly, monolithic, legacy storage platforms. GlusterFS gives users the ability to deploy scale-out, virtualized storage – scaling from terabytes to petabytes in a centrally managed and commoditized pool of storage.

Attributes of GlusterFS include:
 * Scalability and Performance
 * High Availability
 * Global Namespace
 * Elastic Hash Algorithm
 * Elastic Volume Manager
 * Gluster Console Manager
 * Standards-based
Continue Reading...

Wednesday, 6 June 2012

E-Mail count and notifications for Ubuntu desktop - Unity Mail

Unity Mail is an E-Mail count and notifications application for Ubuntu Unity desktop, is a script that checks your mail on any IMAP4-compatible server and displays a notification bubble when you get new mail;

Unity Mail Features:
* Works with any IMAP4-compatible server
* Multiple accounts support
* Unread messages count on the Launcher
* Unity Quick-list support (GMail URLs by default)
* Messaging Menu integration
* NotifyOSD notifications

Unity Mail is written in Python and is currently in Beta development phase.

Continue Reading...

 
//PART 2