-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bash_functions
161 lines (149 loc) · 3.97 KB
/
.bash_functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#
function run() {
number=$1
shift
for n in $(seq $number); do
echo "$n. of $number"
$@
done
}
# get current network info (ip, mac, netmask, broadcast, interface)
function get_network()
{
COMMAND=ifconfig
if [ -z `command -v $COMMAND` ]; then
echo "You should install $COMMAND"
return
fi
local CMD=`which $COMMAND`
local PARAMS=${2:-eth0}
local RESULT=""
case $1 in
interface ) local RESULT="$($CMD -a | awk '/Link encap/ {print $1}' | tr -s '\n' ':')" ;;
ip ) local RESULT="$($CMD $PARAMS | awk '/inet addr/ {print $2}' | awk -F: '{print $2}')" ;;
mac ) local RESULT="$($CMD -a $PARAMS | awk '/HWaddr/ {print $NF}')" ;;
netmask ) local RESULT="$($CMD $PARAMS | awk '/inet addr/ {print $NF}' | awk '/Mask/' | awk -F: '{print $2}')" ;;
broadcast ) local RESULT="$($CMD $PARAMS | awk '/inet addr/ {print $3}' | awk '/Bcast/' | awk -F: '{print $2}')" ;;
* ) local RESULT="" ;;
esac
if [ -z $RESULT ]
then
echo "Usage: get_network {interface,ip,mac,netmask,broadcast} [interface]"
else
echo $RESULT
fi
}
# radio player
function radio_console()
{
PLAYER=mplayer
if command -v $PLAYER >/dev/null; then
local URI=""
case $1 in
bbc1 ) local URI=mms:https://wmlive.bbc.net.uk/wms/bbc_ami/radio1/radio1_bb_live_int_eq1_sl0 ;;
bbc2 ) local URI=mms:https://wmlive.bbc.net.uk/wms/bbc_ami/radio2/radio2_bb_live_int_eq1_sl0 ;;
bbc3 ) local URI=mms:https://wmlive.bbc.net.uk/wms/bbc_ami/radio3/radio3_bb_live_int_eq1_sl0 ;;
bbc4 ) local URI=mms:https://wmlive.bbc.net.uk/wms/bbc_ami/radio4/radio4_bb_live_int_eq1_sl0 ;;
bbc5 ) local URI=mms:https://wmlive.bbc.net.uk/wms/bbc_ami/radio5/radio5_bb_live_int_eq1_sl0 ;;
program1 ) local URI=mms:https://stream.polskieradio.pl/program1 ;;
program2 ) local URI=mms:https://stream.polskieradio.pl/program2 ;;
program3 ) local URI=mms:https://stream.polskieradio.pl/program3 ;;
program4 ) local URI=mms:https://stream.polskieradio.pl/program4 ;;
*) local URI="" ;;
esac
if [ -z $URI ]
then
echo "Usage: radio_console {bbc1,bbc2,bbc3,bbc4,bbc5,program1,program2,program3,program4}"
else
$PLAYER -cache 128 -loop 0 $URI
fi
else
echo "You should install $PLAYER"
fi
}
# search text in files
function include()
{
if [ -z $* ]; then
echo "Usage: include TEXT"
return
fi
MASK=*
TEXT=$1
echo "Searching /$TEXT/ in $MASK"
find . -name "$MASK" -print | xargs grep --color=auto -iRn "$TEXT"
}
# top 10 (or more/less) commands
function top_commands()
{
history | awk '{print $2}' | sort | uniq -c | sort -rn | head $1
}
# get gateway
function gateway()
{
array=( route netstat )
local COMMAND=""
for cmd in "${array[@]}"
do
if [ ! -z `command -v $cmd` ]; then
COMMAND=$cmd
break
fi
done
local CMD=""
case $COMMAND in
route ) local CMD="$COMMAND -n" ;;
netstat ) local CMD="$COMMAND -r" ;;
*) echo "You should install iproute"; return ;;
esac
$CMD | awk '/UG/ {print $2}'
}
function mask2num()
{
echo obase=2.$1|tr . \;|bc|tr -d 0\\n|wc -c
}
# what hosts are up
function hosts()
{
INTERFACES=`get_network interface`
NETMASK=`get_network netmask eth1`
BITS=`mask2num $NETMASK`
GATEWAY=`gateway`
echo "It maybe take a while..."
nmap -sP $GATEWAY/$BITS
}
# what hosts are up
function hosts_wlan0()
{
INTERFACES=`get_network interface`
NETMASK=`get_network netmask wlan0`
BITS=`mask2num $NETMASK`
GATEWAY=`gateway`
echo "It maybe take a while..."
nmap -sP $GATEWAY/$BITS
}
function gg()
{
local REGEXP=""
git grep $REGEXP $(git rev-list --all)
}
function postgis_version()
{
echo `psql $1 -tAc "select postgis_full_version();"`
}
function check_ip()
{
ip=$1;
revdns=$(dig +short -x "$ip");
dns_a=$(dig +short A "$revdns");
echo -e -n "RevDNS: $revdns\nA: $dns_a\nStatus: ";
[[ "$ip" == "$dns_a" ]] && echo "OK" || echo "FAIL";
}
function topp() {
$* &>/dev/null &
pid="$!"
trap ':' INT
echo 'CPU MEM'
while sleep 1; do ps --no-headers -o '%cpu,%mem' -p "$pid"; done
kill "$pid"
}