Mezgani blog

August 16, 2010

Create random password using /dev/urandom

Filed under: bash, linux — Tags: , — Ali MEZGANI @ 11:34 am

In many situation administrators are affronted to generate passwords, however it’s more secure to keep in eyes random password even that ordinarie one.
Well, for such use let’s keep it simple and let’s define some files:

/dev/random: is a special file that serves as a true random number generator or as a pseudorandom number generator.
/dev/urandom: (“unlocked” random source) which reuses the internal pool to produce more pseudo-random bits.

If your system does not have /dev/random and /dev/urandom created already, they can be created with the following commands:
$ mknod -m 644 /dev/random c 1 8
$ mknod -m 644 /dev/urandom c 1 9
$ chown root:root /dev/random /dev/urandom


$ tr -cd a-zA-Z0-9 < /dev/urandom | head -c 12 ; echo ""

March 20, 2010

Number of public IP address in an AS (example IAM)

Filed under: bash, routing — Tags: , , — Ali MEZGANI @ 1:51 pm

You can get the number of public address in an AS by using whois and ipcalc tools like this query :

$ for ip in $(whois -i origin AS6713 | awk ‘/route/ { print $2 }’); do ipcalc $ip; done | awk ‘/\/Net/{ ip+=$2 } END { printf ip “\n” }’

155638

August 2, 2009

Pipes in syslog

Filed under: bash, linux, system — Tags: — Ali MEZGANI @ 11:30 pm

Using syslog, there are a possiblity to write the output to a pipe, so we can read this pipe from a program. But we have to be careful, syslogd should not wedge but we will have missing and/or mangled
messages if they arrive faster than our program can process them.
Let’s take look to how to create these pipes and read from them:

First create a named pipe using mkfifo:
$ mkfifo -p /home/mezgani/syslog.pipe

Make syslog.conf to points to this file:
*.info |/home/mezgani/syslog.pipe

Restart syslog:
$ sudo pkill -HUP syslogd

Create processing script that read the pipe
$ cat > foo
#!/bin/bash
cat /home/mezgani/syslog.pipe | while read input
do
# some stuff
echo ${input}
# ….
done

July 21, 2009

cpan recent modules

Filed under: bash, perl — Tags: , — Ali MEZGANI @ 1:42 am

This command grabs and print the URL of a plain text file that lists new files added to CPAN the past two weeks.
$ perl -MLWP::Simple -e “getprint ‘http://cpan.org/RECENT’&#8221;

You can easily make it part of a tidy little shell command, like this one that mails you the list of new SOAP::modules
$ perl -MLWP::Simple -e “getprint ‘http://cpan.org/RECENT’&#8221; | grep “/by-module/SOAP” | mail -s “New SOAP module! ” $USER

July 16, 2009

Using bash variables in awk

Filed under: bash — Tags: — Ali MEZGANI @ 12:55 pm

First you need to assign the variables with the -v option:
The option -v followed by var=value is an assignment to be done before (the awk program).

Example of use:
This example define a bash file, that look for any entry “address” into the squid’s access file.

$ cat > search
#!/bin/bash
awk -v address=”$1″ ‘$3 == address && $4 ~ /200/’ /var/log/squid/access.log

$ chmod +x search; sudo ./search 192.168.0.2

July 10, 2009

The top 10 of your most used unix commands

Filed under: bash — Ali MEZGANI @ 1:34 am

This tips show you the ten most used unix commands.
Do the following on your console and see what you’re frequently using:

$ history|awk ‘{print $2}’|awk ‘BEGIN {FS=”|”} {print $1}’|sort|uniq -c|sort -rn|head -10

April 12, 2009

mkdir and cd

Filed under: bash — Tags: — Ali MEZGANI @ 1:07 am

Many times, i find myself making and moving to a directory quite a bit, normally I use something like this
$ mkdir ~/dir && cd ~/dir
or
$ mkdir -p create/new/dir && cd create/new/dir
You can’t have a simple BASH script that reads “mkdir $1 && cd $1″ because it would only switch to the directory while running as a child process instead of actually switching to the directory.
However there is a quick and easy way to combine the tasks, add a function mkcd() to your .bashrc.
$ cat >> ~/bashrc
function mkcd(){
[ -n "$1" ] && mkdir -p “$@” && cd “$1″;
}

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.