Appending strings in bash without the line feed.
To append to a stream in bash without the trailing line feed use printf to format the output before appending it to the stream.
1 i=42 2 FILE=/tmp/atm 3 printf "%s" "${i}" > $FILE
How to install sar on Debian
First install the sysstat package which includes sar:
1 apt-get install sysstat
Then run crontab -e and add the following to collect stats:
1 # Collect measurements at 10-minute intervals 2 0,10,20,30,40,50 * * * * /usr/lib/sa/sa1 3 # Create daily reports and purge old files 4 0 0 * * * /usr/lib/sa/sa2 -A
You now have access to IO and CPU usage history.
Compiling xvidcap for making screencasts in wmii
I was unable to make screencasts in wmii using Istanbul. So here’s how I installed xvidcap. Unfortunately I cannot come up with a way for wget retrieval of the sourceball, so some manual labour is needed. Retrieve the sourceball and put it in /tmp. Then follow the instructions below. Also see the snippet for an alias for the make command first.
Note that I put the binaries in /usr/local/stow/xvidcap because the package comes from outside package management. I then use xstow to manage the symlinks in /usr/local/bin.
1 sudo apt-get install libxml-parser-perl libxmu-dev libglade2-dev libgtk2.0-dev 2 cd /tmp 3 tar zxvf xvidcap*.tar.gz 4 cd xvidcap* 5 ./configure --prefix /usr/local/stow/xvidcap 6 make 7 sudo make install 8 cd /usr/local/stow 9 sudo xstow xvidcap
To remove xvidcap follow these steps
1 cd /usr/local/xstow 2 xstow -D xvidcap 3 sudo rm -rf /usr/local/stow/xvidcap
Linux here documents
Simple usage of a here document in Linux.
1 marko@x61s:~$ cat << EOF > /tmp/hubbabubba 2 > hubba 3 > EOF 4 marko@x61s:~$ cat /tmp/hubbabubba 5 hubba
Linux NAT with 3g PPP connection
I run this nat.sh script whenever I need to share my 3g connection to other computers in the switch I’m plugged into. Please note that it resets existing iptables rules.
1 #!/bin/bash 2 iptables --flush 3 iptables --table nat --flush 4 iptables --delete-chain 5 iptables --table nat --delete-chain 6 7 echo 1 > /proc/sys/net/ipv4/ip_forward 8 9 internal=eth0 10 external=ppp0 11 /sbin/iptables -t nat -A POSTROUTING -o ${external} -j MASQUERADE 12 /sbin/iptables -A FORWARD -i ${external} -o ${internal} -m state --state RELATED,ESTABLISHED -j ACCEPT 13 /sbin/iptables -A FORWARD -i ${internal} -o ${external} -j ACCEPT