Tag: script

  • Simple way to get stats from Apache

    This way you can get stats from your logs but this method is a little bit rudimentary as you are going to get visits from crawlers, bots,… that are not real visits. Parse your logs directly with awk. #!/bin/sh echo ‘Number of unique visitors’ cat /var/log/apache/www.yoursite.com-access.log |awk ‘{print $1}’ | sort | uniq | wc…

  • HTTP Proxy Checker in bash

    Usefull script  to check if a proxy is alive. #!/bin/bash # HTTP Proxy Server’s IP Address (or URL) proxy_server=$1 # HTTP Proxy Server’s Port Number port=$2 # We’re trying to reach this url via the given HTTP Proxy Server # (http://www.google.com by default) url=”http://www.google.com” # Timeout time (in seconds) timeout=20 # We’re fetching the return…

  • Google URL shortener script

    Maybe it’s no longer working #!/bin/bash # Google url shortener bash script # For information about the app: # http://ggl-shortener.appspot.com/instructions/ app=’http://ggl-shortener.appspot.com/?url=’ url=”$1″ protocol=`echo “$1” | sed -e “/^http:\/\//g”` if [ -z “$1” ]; then echo -e “you need to pass the url through an argument”; echo -e “e.g. `basename $0` http://url”; else if [ !…

  • 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…

  • 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

  • Find absolute path of Bash script

    You should run this command within a script!   abspath=”$(cd “${0%/*}” 2>/dev/null; echo “$PWD”/”${0##*/}”)”

  • Dirty script to find out free storage space in mount points

    Dirty script to find out free storage space.   for path in `mount | awk ‘/^\/dev/ {print $3}’`; do df -h “$path”; done;

  • Check if an input is numeric or char

     With this script you can check if an argument to a script is numeric, char or alphanumeric. [[ -z “$1” ]] && echo “I cant work without an input” && exit 1 INPUT=”$@” [[ “$INPUT” == ?(+|-)+([0-9]) ]] && echo “$INPUT is numeric” && exit 0 [[ “$INPUT” == +([a-zA-Z]) ]] && echo “$INPUT is…

  • Yes/No GUI dialog with gdialog

    An gdialog example in linux. A dialog prompt for yes or no. #!/bin/bash gdialog –title “some title for the dialog” –yesno “some text \n the yes/no question.” if [ $? == 0 ]; then {commands for yes} else {maybe other commands for no} fi

  • Bash menu in bash with getopts

    A little more sophisticated script than the former bash menu example to get some arguments from command line. #!/bin/bash while getopts “u:p:” opt; do case $opt in u) echo “-u was triggered, Parameter: $OPTARG” dbuser=”$OPTARG” ;; p) echo “-p was triggered, Parameter: $OPTARG” dbpass=”$OPTARG” ;; \?) echo “Invalid option: -$OPTARG” exit 1 ;; 🙂 echo…