Posts

Reading Stdin Bash style

Stephen
Have you ever had the need to read standard input in a bash script, for example cat /var/log/message | mycoolbashscript.sh Well i did when wrapping msmtp for use with mutt see the example bellow #!/bin/bash all=`cat "/dev/stdin"` if `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/awk -F: '{ print $2 }'' | /usr/bin/awk '{ print $1 }'' | /bin/grep -qE '172\.31|32\.[0-9]{1,3}\.[0-9]{1,3}'`; then echo "$all" | tsocks msmtp -a account $* else echo "$all" | msmtp -a account $* fi I then setup mutt to use this as the sendmail binary set sendmail="~/utils/sendmail.

Offlineimap + Mutt = Less Pain

Stephen
I receive a lot of email as im a system administrator in order to handle this i prefer to use Mutt. One problem, Mutt sucks when using imap connections. In order to over come this you can use a nice little util called offlineimap that with sync a imap server to a local folder in mail dir format. So the flow of mail into my computer is now Imap Server -> Offlineimap -> Mutt -> Offlineimap -> Imap Server

Bash and substring removal

Stephen
Deletes shortest match of $substring from back of $string. ${string%”$substring”} Example find /var/files -name "*.mp3" | while read string; do mv$ $string ${string%"mp3"}wav done Will strip mp3 of the end of the string and add wav

Sun java plugin firefox and lucid

Stephen
After upgrading i noticed the sun plugin no longer works in firefox after so poking i got it working using this hack sudo rm /etc/alternatives/mozilla-javaplugin.so sudo ln -s /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so /etc/alternatives/mozilla-javaplugin.so sudo rm /usr/lib/mozilla/plugins/libjavaplugin.so sudo ln -s /etc/alternatives/mozilla-javaplugin.so /usr/lib/mozilla/plugins/libjavaplugin.so

Lucid Windows Control Layout

Stephen
After upgrading to lucid i noticed that they decided to go for the mac layout on windows controls to fix this. Run gconf-editor, then apps > metacity > general > button layout > menu:minimize,maximize,close Fixed thank god.

Powertop

Stephen
PowerTOP is a software utility designed to measure, explain and minimize a computers power consumption. It works for both Intel and AMD processors. It analyses the programs, devices and kernel options running Linux or Solaris. It estimates the power consumption for any computer. This information can be used to find out what programs / devices are using excessive power. The focus of powertop is monitoring CPU sleep states, and showing the programs or drivers responsible for “wakeups” which prevent CPUs entering sleep states.

Irq Fun

Stephen
Hardware interrupts were introduced as a way to avoid wasting the processor’s valuable time in polling loops, waiting for external events. They may be implemented in hardware as a distinct system with control lines, or they may be integrated into the memory subsystem.Read More [root@dfs2 ~]# cat /proc/interrupts CPU0 CPU1 <items removed> 30: 1543015844 70 IO-APIC-level eth0 33: 982 1125222804 IO-APIC-level eth1 NMI: 0 0 LOC: 312789123 312790125 ERR: 0 MIS: 0 As you can see from the list above the interrupts for the network card has been balanced betwen the Cores.

The Most Useful Command Ever

Stephen
How many times have you run a command and then thought, ooo crap i now need to leave work, i really should have nohupped it or run it in screen session well welcome to. disown \[-ar\] \[-h\] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP.

Network Condition Emulation

Stephen
I was asked to today if it was possible to add latency and packet loss to a device in order to replicated network problems. After a while googleing i found tc +netem. This allows you do funcy stuff to replicated network problems. If i wanted to add 100ms of latency i could do tc qdisc add dev eth0 root netem delay 100ms You can also add variation tc qdisc change dev eth0 root netem delay 100ms 10ms

Wonders Of Cssh

Stephen
If you need to run the same commands on multiple computers, then maybe you should be thinking about using puppet but if you only need to do a one time thing then there is clusters ssh aka cssh. After a apt-get install clusterssh You can then start using it by simple typing cssh server01 server02 etc etc Another way to do it is include this in you .csshrc file extra_cluster_file=~/.clusters Then in you ~.