Friday, April 22, 2011

Script to find sum of a word in numbers

Attitude = 100% , Usually we find this in lot of forums or mailing lists.
To calculate this in Linux the below script can be used.

Pass the word as first argument to calculate its sum in words.

#!/bin/bash

initial=1
for alpha in {a..z}
do
let $alpha=$initial
initial=`expr $initial + 1`
done
word="$1"
length=${#word}
base=0
offset=1
final=0
while [ $base -lt $length ]
do
semi=$(($(echo ${word:base:offset})))
let final=`expr $final + $semi`
let base++
done

echo "Numeric value of $word is $final"

Sunday, April 25, 2010

Create local YUM repository from iso

To Create a local yum repository a separate tool createrepo is required.
To install createrepo, mount the iso and type the following commands...
# mkdir -p /mnt/repo/{1,centoscd}
# mount  -o loop /path/to/centos.iso /mnt/repo/1
# rpm -ivh /mnt/repo/1/CentOS/createrepo*.rpm
Now copy the contents from iso to /mnt/repo/centoscd
# cp -rpf /mnt/repo/1/* /mnt/repo/centoscd/
Now create the repository
# cd /mnt/repo
# createrepo .
To clean existing repo cache enter
# yum clean all
Create config file
Add the following text in /etc/yum.repos.d/localiso.repo
[My-local-repository]
baseurl=file:///mnt/repo
enabled=1
Before installing packages GPG key needs to be imported
# rpm --import /mnt/repo/centoscd/RPM-GPG-KEY-CentOS*
Now use yum command to install packages
# yum install package-name

Thursday, August 27, 2009

List only directories in Linux

There are many ways to list only directories in a linux machine.

1) ls -ld /*

2) tree -di

3) ls -l | grep '^d' | awk '{print $8}' ### for Red Hat put $9 & for OpenSuse put $8

SVN book online

This is a place to read HTML and PDF versions of the book: http://svnbook.red-bean.com/

Wednesday, August 12, 2009

What is epoch time?

The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1-1-1970), but 'epoch' is often used as a synonym for 'Unix time'. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).

Human readable time  Seconds
1 minute 60 seconds
1 hour 3600 seconds
1 day 86400 seconds
1 week 604800 seconds
1 month (30.44 days) 2629743 seconds
1 year (365.24 days) 31556926 seconds

More info on epoch can be read at http://www.epochconverter.com/