Category: bash

  • Installing Lamp on Ubuntu

    Some apt and tasksel magic. If you want to have an apache server with mysql and php ready to work in ubuntu is as easy as:   sudo apt-get install tasksel sudo tasksel install lamp-server

  • Transfer files via ssh with rsync

    Prefered method if ssh is available. Another way, if you have SSH: rsync -aE -e ssh directory user@hostB:target_dir or from hostB rsync -aE -e ssh user@hostA:directory target_dir You can also use the z (–compress) switch to rsync if network throughput is an issue.

  • Mount Share Network Event Triggered Bash Script

    What this script does is, check the gateway mac address to find out if you are within your lan or in a different place. If at home, mount a share as normal. If away, mount that share as a ssh file system. #!/bin/bash gateway=$(ip route show 0.0.0.0/0 | awk ‘{print $3}’) mactest=$(arp -n -a $gateway…

  • Format find and awk output locating large files

    Use find to locate files over a criteria size and format output with awk. Changing value of NF variable you change fields separator   find / -type f -size +20000k -exec ls -lh {} \; | awk ‘{ print $NF “: ” $5 }’

  • Ssh port forwarding

    With this command you can tunnel your communications if you set software to connect to localhost 127.0.0.1 port 9999 ssh -D 9999 [email protected]  

  • Reconfigure timezone on Debian

    Use dpkg-reconfigure to change time zone on Debian dpkg-reconfigure tzdata  

  • Ignore Ssh host key

    Sometimes when you connect to a ssh server whois host key has changed, ssh client warns you about it. If you want to ignore that advice use StictHostkeyChecking no option. ssh -o ‘StrictHostKeyChecking no’ [email protected]

  • MySQL dump tables matching a pattern

    Quick command to dump all tables matching a like pattern. In the example drop tables option is added with xargs. mysql $DB -u$USERNAME -p$PASSWORD -e ‘show tables like “$LIKE%”‘ | grep -v Tables_in | xargs mysqldump –add-drop-table $DB -u$USERNAME -p$PASSWORD

  • Auto aliasing of ssh hosts

    A if [ -d ~/.ssh ]; then # Touch files we expect to exist if [ ! -e ~/.ssh/config ]; then touch ~/.ssh/config; fi if [ ! -e ~/.ssh/known_hosts ]; then touch ~/.ssh/known_hosts; fi # Parse ~/.ssh/known_hosts and ~/.ssh/config to find hosts for x in `sed -e ’s/[, ].*//’ ~/.ssh/known_hosts; awk ‘/^Host [^*?]+$/{print $2}’ ~/.ssh/config`; do # Don’t override commands…

  • Delete Matching Mail in sendmail queue

     Quick script to delete matching emails in sendmail queue. Really usefull when an account has been hacked and you have thounsands of spam emails in the queue. #!/bin/sh cd /var/spool/mqueue for i in `grep -sl “” qf*` do j=`ls -1 “$i” | sed ‘s/qf\(.*\)$/df\1/’` echo “Deleting $i ($j)” rm $i $j done