About Me

- A little contribution to the linux newbies.

Wednesday, June 16, 2010

Script to display all duplicate line in a file once

this script will display all the duplicate lines only once

Example:

$cat file
I like oranges
I like apples
I like pears
I like apples
I like guavas
I like oranges
I like apples

$./test.pl file

I like apples
I like oranges




#!/usr/bin/perl
#
open(FILE,"$ARGV[0]");
my @contents = ;
my %dup;
foreach $line (@contents)
{
@keyz = keys %dup;
if(!(grep(/$line/, @keyz)) || $dup{$line})
{
$dup{$line}++;
if($dup{$line} > 1)
{
print $line;
$dup{$line} = 0;
}
}
}


Tuesday, June 15, 2010

Script to upload ssh key to skip password authentication



#!/bin/bash

## Script to auto upload ssh keys on the LINUX HOST

NO_ARGS=0
E_OPTERROR=65

if [ $# -eq "$NO_ARGS" ] # should check for no arguments
then
echo "Usage: `basename $0` -i "
exit $E_OPTERROR
fi

while getopts ":ih" Option

do
case $Option in

i)
remote_host_ipaddress="$2"
;;

h)
echo "Usage: `basename $0` -i "
exit $E_OPTERROR
;;
esac
done

shift $(($OPTIND - 1))

## This will generate ssh key on the remote host
echo "Generation ssh-keygen on remote linux host"
echo $remote_host_ipaddress

ssh root@$remote_host_ipaddress /usr/bin/ssh-keygen -t dsa

echo "uploading your ssh keys on remote linux host"
scp ~/.ssh/id_dsa.pub root@$remote_host_ipaddress:/root/.ssh/authorized_keys