SRE engineer Bookmarks

I’m Linux system engineer and I develop in Python, Bash and Perl. I’m really interested by SRE position for that, I’m applying for SRE Engineer in Google and production Engineer in facebook. and here I share my daily bookmarks :



Create random password using /dev/urandom

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 ""

Pipes in syslog

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
cat /home/mezgani/syslog.pipe | while read input
# some stuff
echo ${input}
# ….

cpan recent modules

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 ‘'&#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 ‘'&#8221; | grep “/by-module/SOAP” | mail -s “New SOAP module! ” $USER

Using bash variables in awk

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
awk -v address=”$1″ ‘$3 == address && $4 ~ /200/’ /var/log/squid/access.log

$ chmod +x search; sudo ./search