Tag Archives: 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.

 bash | 
 
 copy code |
?

1
#!/bin/sh
2
3
4
echo 'Number of unique visitors'
5
6
cat /var/log/apache/www.yoursite.com-access.log |awk '{print $1}' | sort | uniq | wc -l
7

HTTP Proxy Checker in bash

Usefull script  to check if a proxy is alive.

echo 'Ip of unique visitors'
02
cat cat /var/log/apache/www.yoursite.com-access.log |awk '{print $1}' | sort | uniq | wc -l |awk '{print $1}' | sort | uniq
03
 bash | 
 
 copy code |
?

01
#!/bin/bash
04
05
# HTTP Proxy Server's IP Address (or URL)
06
proxy_server=$1
07
08
09
# HTTP Proxy Server's Port Number
10
port=$2
11
12
13
# We're trying to reach this url via the given HTTP Proxy Server
14
15
# (http://www.google.com by default)
16
url="http://www.google.com"
17
18
19
# Timeout time (in seconds)
20
timeout=20
21
22
# We're fetching the return code and assigning it to the $result variable
23
result=`HEAD -d -p http://$proxy_server:$port -t $timeout $url`
24
25
# If the return code is 200, we've reached to $url successfully
26

Google URL shortener script

Maybe it’s no longer working

if [ "$result" = "200 OK" ]; then
02
    echo "1 (proxy works)"
03
# Otherwise, we've got a problem (either the HTTP Proxy Server does not work
04
# or the request timed out)
05
06
else
07
    echo "0 (proxy does not work or request timed out)"
08
fi
09
10
 bash | 
 
 copy code |
?

01
#!/bin/bash
11
# Google url shortener bash script
12
# For information about the app:
13
result=`HEAD -d -p http://$proxy_server:$port -t $timeout $url`
14
15
app='http://ggl-shortener.appspot.com/?url='
16
url="$1"
17
protocol=`echo "$1" | sed -e "/^http:///g"`
18
19
if [ -z "$1" ]; then
20
 echo -e "you need to pass the url through an argument";
21
# If the return code is 200, we've reached to $url successfully

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.

else
02
 if [ ! "$protocol" ]; then
03
 curl -s "$app$url" | sed -e 's/{"short_url":"//' -e 's/"}/n/g' 
04
 else
05
 repl=`echo "$1" | sed -e 's/^/http:///g'`
06
 curl -s "$app$repl" | sed -e 's/{"short_url":"//' -e 's/{"error_message":"Bad request/error: bad r威而鋼
07
equest/' -e 's/"}/n/g'
08
 fi;
09
else
10
 bash | 
 
 copy code |
?

01
#!/bin/bash
11
gateway=$(ip route show 0.0.0.0/0 | awk '{print $3}')
12
mactest=$(arp -n -a $gateway | awk '{print $4}')
13
targetmac="XX:XX:XX:XX:XX:XX"
14
homeup="mount -t cifs -o username=USER,password=PASSWORD //SERVER/SHARE /mnt/remote"
15
awayup="sshfs my.dyndns.tld:/path/to/share /mnt/remote"
16
targetmac="XX:XX:XX:XX:XX:XX"
17
if [ $mactest==$targetmac ]
18
result=`HEAD -d -p http://$proxy_server:$port -t $timeout $url`
19
 bash | 
 
 copy code |
?

01
#!/bin/bash
20
         up)
21
                $homeup
22
         ;;
23
         down)
24
                $down
25
         ;;
26
if [ $mactest==$targetmac ]
27
# If the return code is 200, we've reached to $url successfully
28
29
 case "$2" in
30

2
3
 $awayup
4
 ;;
5
 down)
6
 $down
7
 ;;
8
 esac
9
fi