luni, 31 ianuarie 2011

Exemple de automatizari in BASH

Au ramas nepostate cateva scripturi pe care le-am facut de-a lungul timpului pentru conky sau chiar pentru utilizare directa in consola, asa ca, tu, cel care cauta pe google, daca ai ajuns aici, te poti folosi cu incredere de aceste exemple.
Pot fi folosite si pe post de template din care sa te inspiri in creearea altor scripturi BASH.


Monitor internet:
(te poate ajuta la identificarea problemelor de conectare la ISP)

#! /bin/bash
# Script de diagnostic al punctelor importante din conexiunea la internet
# Pentru conexiunea externa am folosit unul din ip-urile google-ului
if ping -c 1 -w 1 209.85.229.104 > /dev/null; then
echo "INTERNET ON"
echo "x" > /tmp/netok
else
echo "INTERNET OFF"
rm -f /tmp/netok
fi
if ping -c 1 -w 1 $(cat /etc/resolv.conf | grep -m 1 nameserver | awk '{ print $2}') > /dev/null; then
echo "DNS/ISP GOOD"
else
echo "DNS/ISP BAD"
fi
if ping -c 1 -w 1 $(route -n | grep 'UG' | cut -d: -f2 | awk '{ print $2}') > /dev/null; then
echo "GATEWAY GOOD"
else
echo "GATEWAY BAD"
fi

Ultimele postari active din forum.ubuntu.ro:



#!/bin/bash
numarlinii=5
wget -q http://forum.ubuntu.ro/rss.php -O /tmp/rss.php
cat /tmp/rss.php | grep "description>Topic:" | cut -d"<" -f2 | cut -d">" -f2 | while read line; do
echo $line | sed 's/Topic: /</'| cut -d"<" -f2 | gawk '{
while (match($0,/&#[0-9]+;/))
$0 = substr($0, 1, RSTART-1) sprintf("%c", substr($0, RSTART+2)+0) \
substr($0, RSTART+RLENGTH)
print
}' >> /tmp/content
done
cat /tmp/content | awk '{
if ($0 in stored_lines)
x=1
else
print
stored_lines[$0]=1
}'| head -n $numarlinii
rm -f /tmp/content
rm -f /tmp/rss.php
Extragerea IP-ului WAN curent:

#!/bin/bash
wget http://checkip.dyndns.org/ -q -O - |
grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'

In .conkyrc introduceti:



${if_existing /proc/net/route eth0}${font Ubuntu:size=8}WAN IP: ${execi 60 ~/cnkscr/ipshow}${endif}
Lista calculatoare LAN active:
(inlocuiti ip-urile si numele dupa preferinte)

#! /bin/bash
# Script de diagnostic al lan-ului
# Creat pentru conky de Dan Radu in iunie 2010
#echo "Checking hosts..." | zenity --progress --title="Working..." --auto-close
cat /dev/null > /tmp/lanlist
if ping -c 1 -w 1 192.168.123.5 > /tmp/valoare; then
echo "Laptop WIFI " $(cat /tmp/valoare | grep ttl | awk '{ print $7}' | cut -d"=" -f2 ) "ms" >> /tmp/lanlist
fi
if ping -c 1 -w 1 192.168.123.6 > /tmp/valoare; then
echo "Laptop ETH " $(cat /tmp/valoare | grep ttl | awk '{ print $7}' | cut -d"=" -f2 ) "ms" >> /tmp/lanlist
fi
if ping -c 1 -w 1 192.168.123.3 > /tmp/valoare; then
echo "Desktop1 ETH " $(cat /tmp/valoare | grep ttl | awk '{ print $7}' | cut -d"=" -f2 ) "ms" >> /tmp/lanlist
fi
if ping -c 1 -w 1 192.168.123.4 > /tmp/valoare; then
echo "Laptop2 WIFI " $(cat /tmp/valoare | grep ttl | awk '{ print $7}' | cut -d"=" -f2 ) "ms" >> /tmp/lanlist
fi
if ping -c 1 -w 1 192.168.123.7 > /tmp/valoare; then
echo "Laptop2 ETH " $(cat /tmp/valoare | grep ttl | awk '{ print $7}' | cut -d"=" -f2 ) "ms" >> /tmp/lanlist
fi
rm -f /tmp/valoare
if [ $(wc -l /tmp/lanlist | cut -d" " -f1) -gt 0 ]; then
#txtbuf=$(cat /tmp/lanlist)
cat /tmp/lanlist
rm -f /tmp/lanlist
else
echo "NO KNOWN LAN COMPUTER ONLINE"
rm -f /tmp/lanlist
fi

Lista conexiunilor "TCP-IP Incoming" cu rezolvarea numelui de domeniu:


#!/bin/bash
numarlinii=10
netstat -nat | grep ESTABLISHED | awk '{ print $5}' |cut -d":" -f1 | head -n $numarlinii > /tmp/honk
cat /tmp/honk | while read line; do
whois $(echo $line)| egrep -i "address|netname" > /tmp/whoz
if [ $(wc -l /tmp/whoz | cut -d" " -f1) -gt 0 ]; then
echo $(echo $line)" - "$(cat /tmp/whoz | grep -i netname | awk '{ print $2}') $(cat /tmp/whoz | grep -i address | awk '{ print $2,$3,$4,$5}' ) >> /tmp/listazone
fi
done
if [ -f /tmp/listazone ]; then
echo "nimic" > /dev/null
else
echo "NO CONNECTIONS FOR NOW*"
exit
fi
if [ $(wc -l /tmp/listazone | cut -d" " -f1) -gt 0 ]; then
cat /tmp/listazone
rm -f /tmp/whoz
rm -f /tmp/listazone
else
echo "NO CONNECTIONS FOR NOW"
rm -f /tmp/whoz
rm -f /tmp/listazone
fi


Share this on: Share On Facebook ! Add To Del.icio.us ! Share On Digg ! Share On StumbleUpon ! Blog Feed !

3 comentarii:

Juane Zeg spunea...

under armour basketball shoes
ferragamo belts
nike free
coach purses sale
north face coats for women
joes new balance outlet
timberland outlet
coach outlet
coach handbags
north face jackets clearance
christian louboutin shoes
coach factory outlet
jordan retro 11
ugg boots sale
nike stores
ferragamo outlet online
coach factory outlet online
cheap jordan shoes
cheap nfl
celine handbags
coach factory store
kate spade clearance
prada shoes
fitflop shoes sale
the north face sale
oakley sunglasses outlet
jordan retro 11
canada goose outlet
fitflop sale
columbia outlet
nike shoes outlet
burberry outlet
hermes bag
gucci belts
michael kors outlet store
fitflops sandals for women
new balance running shoes
michael kors handbags
jordan 11
coach bags
canada goose jacket sale
coach factory outlet
north face jacket
womens north face jackets sale
jordan retro 11 legend blue
20151010yxj

Rer Dfwet spunea...

fitflop sandals for women
coach factory outlet online store
canada goose for sale
kd shoes
coach wallets
toms outlet
coach handbags online outlet
louis vuitton outlet
coach factory outlet online
joe's new balance
ralph lauren factory
air jordan 6
supra for sale
burberry outlet
converse sale clearance
jordans for girls
www.gucci.com
toms outlet
north face factory outlet
toms shoes
canada goose clearance
fitflops sale clearance
canada goose jackets
michael kors outlet store
louboutin outlet
michael kors sale
columbia clothing outlet
columbia outlet
new balance
coach shoes for women
red sole shoes christian louboutin
vans shoes sale
nike air max 2015
michael kors outlet store
christian louboutin shoes
coach tote
coach bags 1027lxy

Nnae Onnwe spunea...

oakley sunglasses
chanel bags
jordan 6
christian louboutin outlet
kate spade outlet
burberry sale
nike outlet online
juicy couture outlet online
polo shirt
coach bags outlet
mbt shoes clearance outlet
michael kors handbags outlet stores
coach factory outlet
nike heels
cheap vans
nike shoes
tods shoes
cheap jordan shoes
supras
fitflop
fitflop sale
air jordan 13
hermes belt
clarks shoes clearance
the north face outlet
burberry handbags
coach handbags
gucci.com
coach outlet online
puma shoes
coach factory online
coach bags sale
cheap purses michael kors
coach wallets
juicy couture outlet
fitflops sandals for women
ferragamo outlet 1027lxy

Trimiteți un comentariu