Personal tools

Difference between revisions of "Scripturi BASH"

From linux360

Jump to: navigation, search
(Ca sa arate mai colorat...)
 
(16 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
== Exemple scripturi BASH ==
 
== Exemple scripturi BASH ==
 +
 +
=== Scripturi care permit schimbarea rapida a MAC+IP ===
 +
 +
[[User:Raptor360|Raptor360]] 12:33, 8 June 2006 (EEST)
 +
 +
====getmac====
 +
 +
Primeste ca parametru un IP si returneaza MAC-ul acestuia sau "" daca nu exista in retea nodul cu pricina.
 +
 +
''/usr/local/bin/getmac''<code bash>#!/bin/sh
 +
 +
if [[ ! $IFDEVICE ]]; then
 +
        IFDEVICE="eth0";
 +
fi
 +
 +
mac=`arping -I $IFDEVICE $1 -c 3 | grep reply | cut -f2 -d\[ | cut -f1 -d\] | uniq`
 +
echo $mac</code>
 +
 +
====be====
 +
Primeste ca parametru un IP si schimba MAC-ul si IP-ul pentru un device.
 +
 +
''/usr/local/bin/be''<code bash>#!/bin/bash
 +
 +
if [[ ! $IFDEVICE ]]; then
 +
        IFDEVICE="eth0"
 +
fi
 +
 +
gip=`echo -e "$1\t"`
 +
echo -e " IP is $1."
 +
mac=`cat /etc/stored | grep "$gip" | cut -f2`
 +
echo -e "MAC is $mac."
 +
if [[ $mac != "" ]]; then
 +
        ifconfig $IFDEVICE down
 +
        ifconfig $IFDEVICE hw ether $mac
 +
        ifconfig $IFDEVICE $1 netmask 255.255.248.0 broadcast 10.10.17.255
 +
        route add default gw 10.10.17.1
 +
        # echo "nameserver 10.10.17.1" > /etc/resolv.conf
 +
else
 +
        echo "$1 has not an associated MAC."
 +
fi</code>
 +
 +
====switchuser====
 +
 +
Schimba MAC-ul si IP-ul aleator conform unuia stocat in /etc/stored folosind scripturile anterioare.
 +
 +
''/usr/local/bin/switchuser''<code bash>#!/bin/bash
 +
 +
notfound=1
 +
while [[ $notfound -eq 1 ]]; do
 +
        rip=`echo "$RANDOM % 252 + 3" | bc`
 +
        for i in `seq $rip 254`; do
 +
                randip="10.10.17.$i"
 +
                gip=`echo -e "$randip\t"`
 +
                if [[ `cat /etc/stored | grep "$gip" | cut -f2` != "" ]]; then
 +
                        if [[ `getmac $randip` == "" ]]; then
 +
                                be $randip
 +
                                exit 0
 +
                                notfound=1
 +
                        else
 +
                                echo "IP $randip is already active."
 +
                        fi
 +
                else
 +
                        echo "$randip has no MAC associated."
 +
                fi
 +
        done
 +
done</code>
 +
 +
Scripturile folosesc fisierul de configurare ''/etc/stored'' in care se adauga perechi de forma: IP\tMAC, e.g. <code>10.10.17.241    00:20:ED:95:2A:A1
 +
10.10.17.242    4C:00:10:53:BF:A5</code> precum si variabila din enviroment IFDEVICE daca este definita. e.g. daca vrem sa schimbam ip-ul doar pentru device-ul eth1 atunci apelam la:
 +
<code># IFDEVICE=eth1 switchuser </code>
 +
 +
=== Script care lanseaza in fundal o anumita comanda data ca parametru de intrare ===
 +
Puteti lasa o comanda sa se execute in fundal fara ca ea sa fie intrerupta la
 +
iesirea dumneavoastra din sistem folosind urmatorul script pe care l-am numit
 +
silent. (output-ul nu este salvat, pentru aceasta puteti folosi nohup)
 +
 +
<code bash>#!/bin/bash
 +
 +
echo "Executing \"$*\""
 +
setsid bash -c $* 2>>/dev/null 1>>/dev/null < /dev/null &</code>
 +
 +
Scriptul il puteti folosi de exemplu:
 +
 +
<code>$ silent wget -c -t 0 www.bigfiles.com/ubuntu.iso</code>
  
 
=== Script ce elimina zona asociata unui domeniu dat ca parametru de intrare ===
 
=== Script ce elimina zona asociata unui domeniu dat ca parametru de intrare ===
Line 7: Line 91:
 
până la acolada închisă asociată acoladei deschise de mai sus.
 
până la acolada închisă asociată acoladei deschise de mai sus.
  
Scriptul este:
+
Scriptul este:<code bash>#!/bin/bash
#!/bin/bash
+
 
+
# Bind zone remove script
# Bind zone remove script
+
#
#
+
# Copyright (C) 2005 Silvian Cretu <silvian86@yahoo.com>
# Copyright (C) 2005 Silvian Cretu <silvian86@yahoo.com>
+
#
#
+
# This program is free software; you can redistribute it and/or
# This program is free software; you can redistribute it and/or
+
# modify it under the terms of the GNU General Public License
# modify it under the terms of the GNU General Public License
+
# as published by the Free Software Foundation; either version 2
# as published by the Free Software Foundation; either version 2
+
# of the License, or (at your option) any later version.
# of the License, or (at your option) any later version.
+
#
#
+
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+
# GNU General Public License for more details.
# GNU General Public License for more details.
+
#
#
+
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
+
# along with this program; if not, write to the Free Software
# along with this program; if not, write to the Free Software
+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
+
 
+
if [ ! $# = 1 ]; then
if [ ! $# = 1 ]; then
+
    echo "Usage: $0 domain";
    echo "Usage: $0 domain";
+
    echo "The path to named.conf is defined inside the script";
    echo "The path to named.conf is defined inside the script";
+
    else
    else
+
pathToNamedDotConf=/etc/named.conf
pathToNamedDotConf=/etc/named.conf
+
+
x=$(grep -n "zone \"$1\" {" $pathToNamedDotConf | cut -f1 -d:)
x=$(grep -n "zone \"$1\" {" $pathToNamedDotConf | cut -f1 -d:)
+
sed $x,/\}\;/d $pathToNamedDotConf > temp
sed $x,/\}\;/d $pathToNamedDotConf > temp
+
c=$(sed -n $x'p' < temp)
c=$(sed -n $x'p' < temp)
+
if [ "x`echo $c | grep "zone"`" = "x" ]
if [ "x`echo $c | grep "zone"`" = "x" ]
+
then
then
+
sed $x' d' temp > $pathToNamedDotConf
sed $x' d' temp > $pathToNamedDotConf
+
else
else
+
cat temp > $pathToNamedDotConf
cat temp > $pathToNamedDotConf
+
fi
fi
+
rm -f temp
rm -f temp
+
exit
exit
+
fi</code>
fi
 
  
 
=== Cautarea unui fisier ce contine un anumit string ===
 
=== Cautarea unui fisier ce contine un anumit string ===
  
find /path -name "*" -exec grep -H "&amp;amp;amp;amp;lt;string&amp;amp;amp;amp;gt;"  '{}' \;
+
<code bash>find /path -name "*" -exec grep -H "<string>"  '{}' \;</code>
 
sau
 
sau
grep -Hr "&amp;amp;amp;amp;lt;string&amp;amp;amp;amp;gt;" /path/
+
<code bash>grep -Hr "<string>" /path/</code>
  
Fireste, <tt>&amp;amp;amp;amp;lt;string&amp;amp;amp;amp;gt;</tt> poate fi atat un sir de caractere cat si orice fel de expresie regulata suportata de versiunea particulara de <tt>grep</tt> disponibila pe masina in cauza.<br />
+
Fireste, <tt>&lt;string&gt;</tt> poate fi atat un sir de caractere cat si orice fel de expresie regulata suportata de versiunea particulara de <tt>grep</tt> disponibila pe masina in cauza.<br />
Deasemenea, pentru a cauta fara a face diferenta intre majuscule si minuscule, adaugati parametrul <tt>-i</tt> la <tt>grep</tt>.
+
Deasemenea, pentru a cauta fara a face diferenta intre majuscule si minuscule, adaugati parametrul <tt>-i</tt> la <tt>grep</tt>.  
 +
 
 +
Daca doriti ca in output-ul comenzii <tt>grep</tt> expresia cautata sa fie cautata sa fie evidentiata puteti folosi parametrul <tt>--color</tt> astfel:
 +
<code bash>grep --color -Hr "<string>" /path/</code>
  
 
=== Stergerea fisierelor backup ===
 
=== Stergerea fisierelor backup ===
Line 61: Line 147:
 
Nu ar fi prea placut sa aveti un <tt>index.php~</tt>  in <tt>DocumentRoot</tt>
 
Nu ar fi prea placut sa aveti un <tt>index.php~</tt>  in <tt>DocumentRoot</tt>
  
find /path -name "*~" -exec rm -f '{}' \;
+
<code bash>find /path -name "*~" | xargs -n 20 rm -f</code>
  
 
=== Probleme cu spatiul pe disc? ===
 
=== Probleme cu spatiul pe disc? ===
Line 68: Line 154:
 
Linia urmatoare va ajuta, facand totodata si o sortare.
 
Linia urmatoare va ajuta, facand totodata si o sortare.
  
<pre>du --max-depth=1 /path | sort -rn</pre>
+
<code bash>du --max-depth=1 /path | sort -rn</code>
 +
 
 +
=== Gasirea fisierelor duplicate intr-un director ===
 +
Aveti prea multe mp3-uri si majoritatea sunt duplicate dar cu alt nume sau orice de genul folositi scriptul de mai jos:D Eventual adaugati si un -maxdepth 1 sa nu fie recursiv.
 +
<code bash>
 +
#!/bin/sh
 +
if [ ! -d "$1" ]; then
 +
  echo "Usage $0 <dir>"
 +
  exit 1
 +
fi
 +
find "$1" -type f -print0 |  xargs -0 -n1 md5sum |    sort --key=1,32 | uniq -w 32 -d --all-repeated=prepend \
 +
                                    |cut -f3- -d' '|sed 's/^$/Fisiere identice:/'
 +
</code>
 +
 
 +
=== Calcularea recordului de uptime ===
 +
 
 +
Scriptul urmator va trebui plasat in crontab astfel incat sa ruleze periodic, de exemplu, din ora in ora. El va afisa in fisierul ''$output'' (initial ''/var/log/uptimeRecord.log'') output-ul comenzilor ''uptime'' si ''date'' (adica uptime-ul record si data la care a fost inregistrat).
 +
 
 +
<code bash>#!/bin/bash
 +
 
 +
# Copyright (C) 2006 Silvian Cretu <silvian86@yahoo.com>
 +
#
 +
# This program is free software; you can redistribute it and/or
 +
# modify it under the terms of the GNU General Public License
 +
# as published by the Free Software Foundation; either version 2
 +
# of the License, or (at your option) any later version.
 +
#
 +
# This program is distributed in the hope that it will be useful,
 +
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +
# GNU General Public License for more details.
 +
#
 +
# You should have received a copy of the GNU General Public License
 +
# along with this program; if not, write to the Free Software
 +
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 +
 
 +
output='/var/log/uptimeRecord.log'
 +
 
 +
function compareHrs
 +
{
 +
        uptimeCurent=`uptime`
 +
        if [ `echo $uptimeCurent | grep -c day` == '0' ]; then
 +
#              echo Uptime mai mic de o zi
 +
                uptimeCurentOre=`uptime | awk '{print $3}'`
 +
                uptimeRecordOre=`cat $output | head -1 | awk '{print $3}'`
 +
        else
 +
                uptimeCurentOre=`uptime | awk '{print $5}'`
 +
                uptimeRecordOre=`cat $output | head -1 | awk '{print $5}'`
 +
        fi
 +
        if [ `expr length $uptimeCurentOre` \> `expr length $uptimeRecordOre` ]; then
 +
#              echo Nou record - Uptime curent mai mare cu cateva ore decat uptime-ul record 1
 +
                uptime > $output
 +
                date >> $output
 +
        else
 +
                if [ `expr length $uptimeCurentOre` == `expr length $uptimeRecordOre` ]; then
 +
                        uptimeCurentOra=`echo $uptimeCurentOre | cut -d":" -f1`
 +
                        uptimeRecordOra=`echo $uptimeRecordOre | cut -d":" -f1`
 +
                        if [ $uptimeCurentOra -gt $uptimeRecordOra ]; then
 +
#                              echo Nou record - Uptime curent mai mare cu cateva ore decat uptime-ul record 2
 +
                                uptime > $output
 +
                                date >> $output
 +
                        fi
 +
                fi
 +
        fi
 +
}
 +
 
 +
if [ -a $output ]; then
 +
        uptimeCurent=`uptime`
 +
        uptimeRecord=`cat $output | head -1`
 +
        if [ `echo $uptimeCurent | grep -c day` == '0' ]; then
 +
#              echo Uptime mai mic de o zi
 +
                if [ `echo $uptimeRecord | grep -c day` == '0' ]; then
 +
#                      echo Uptime record mai mic de o zi, comparam orele
 +
                        compareHrs
 +
#              else
 +
#                      echo Uptime record mai mare ca uptime curent
 +
                fi
 +
        else
 +
#              echo Uptime mai mare de o zi
 +
                if [ `echo $uptimeRecord | grep -c day` == '0' ]; then
 +
#                      echo Uptime record mai mic de o zi
 +
                        uptime > $output
 +
                        date >> $output
 +
                else
 +
                        uptimeCurentZile=`uptime | awk '{print $3}'`
 +
                        uptimeRecordZile=`cat $output | head -1 | awk '{print $3}'`
 +
                        if [ $uptimeCurentZile -eq $uptimeRecordZile ]; then
 +
#                              echo Uptime in zile egal
 +
                                compareHrs
 +
                        else
 +
                                if [ $uptimeCurentZile -gt $uptimeRecordZile ]; then
 +
#                                      echo Record nou
 +
                                        uptime > $output
 +
                                        date >> $output
 +
                                fi
 +
                        fi
 +
                fi
 +
        fi
 +
else
 +
#      echo Fisierul nu exista, deci trebuie creat. Recordul e uptime-ul curent
 +
        uptime > $output
 +
        date >> $output
 +
fi
 +
 
 +
exit 0
 +
 
 +
</code>
 +
 
 +
=== Stergere directoare vechi de pe o partiţie pentru salvarea spaţiului ===
 +
 
 +
Scriptul următor poate fi plasat în cron şi rulat cam din oră în oră pentru a şterge directoare vechi. Un exemplu clasic este ştergerea jpeg-urilor generate de cameră de supraveghere conectată la un server Linux:
 +
 
 +
<code bash>#!/bin/bash
 +
 
 +
# Copyright (C) 2005-2007 Silvian Cretu <silvian86@yahoo.com>
 +
#
 +
# This program is free software; you can redistribute it and/or
 +
# modify it under the terms of the GNU General Public License
 +
# as published by the Free Software Foundation; either version 2
 +
# of the License, or (at your option) any later version.
 +
#
 +
# This program is distributed in the hope that it will be useful,
 +
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +
# GNU General Public License for more details.
 +
#
 +
# You should have received a copy of the GNU General Public License
 +
# along with this program; if not, write to the Free Software
 +
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 +
 
 +
# Constante:
 +
partitie=/var/www # partitia monitorizata
 +
procentMaxim="97%" # procentul maxim de ocupare acceptat pt partitia monitorizata
 +
X=1 # se vor sterge directoarele mai vechi de X zile
 +
director=/var/www/html/camera/events/2 # directorul din care se vor sterge subdirectoarele
 +
 
 +
# Cat de ocupata este partitia monitorizata (in procente):
 +
procentOcupare=$(df -h | grep $partitie | awk '{print $5}')
 +
 
 +
if [[ "$procentMaxim" < "$procentOcupare" ]] || [ "$procentOcupare" == "100%" ];
 +
then # trebuie sterse directoarele mai vechi de X zile
 +
find $director -type d -mtime +$X -exec rm -rf {} \;
 +
fi
  
 +
exit
 +
</code>
 
[[Category:Collection]]
 
[[Category:Collection]]
 
[[Category:Programming]]
 
[[Category:Programming]]
<div id="aflknwerkamfs" style="overflow:auto;height:1px;">[http://www.zip.dk/gaeste/bog.php3?id=25415 8 borang permohonan spa] [http://www.zip.dk/gaeste/bog.php3?id=25414 med sona spa] [http://www.zip.dk/gaeste/bog.php3?id=25413 conair foot massaging productpage spa] [http://www.zip.dk/gaeste/bog.php3?id=25412 hotel pittsburgh spa] [http://www.zip.dk/gaeste/bog.php3?id=25411 hot spa springs] [http://www.zip.dk/gaeste/bog.php3?id=25410 day new spa york] [http://www.zip.dk/gaeste/bog.php3?id=25409 hot install replace spa tub] [http://www.zip.dk/gaeste/bog.php3?id=25408 hotel philadelphia spa] [http://www.zip.dk/gaeste/bog.php3?id=25407 day dc spa washington] [http://www.zip.dk/gaeste/bog.php3?id=25406 angeles day los spa] [http://www.zip.dk/gaeste/bog.php3?id=25405 certificate gift spa] [http://www.zip.dk/gaeste/bog.php3?id=25404 dealer pool spa] [http://www.zip.dk/gaeste/bog.php3?id=25403 boob bra ocean pool water] [http://www.zip.dk/gaeste/bog.php3?id=25402 clothes in pool] [http://www.zip.dk/gaeste/bog.php3?id=25401 play a free online pool game] [http://www.zip.dk/gaeste/bog.php3?id=25400 above build ground install pool swimming] [http://www.zip.dk/gaeste/bog.php3?id=25399 polyurethane reaction injection molding] [http://www.zip.dk/gaeste/bog.php3?id=25398 g5 laser logitech mouse] [http://www.zip.dk/gaeste/bog.php3?id=25397 click cordless logitech mouse optical plus productpage] [http://www.zip.dk/gaeste/bog.php3?id=25396 batt insulation poured rolled upgrade] [http://www.zip.dk/gaeste/bog.php3?id=25395 fiberglass insulation roll] [http://www.zip.dk/gaeste/bog.php3?id=25394 insulation plastic window] [http://www.zip.dk/gaeste/bog.php3?id=25393 cold heat insulation material whol] [http://www.zip.dk/gaeste/bog.php3?id=25392 high insulation temperature] [http://www.zip.dk/gaeste/bog.php3?id=25391 blowing insulation machine] [http://www.zip.dk/gaeste/bog.php3?id=25390 guitar string tighteners] [http://www.zip.dk/gaeste/bog.php3?id=25389 how to change electric guitar string] [http://www.zip.dk/gaeste/bog.php3?id=25388 box comment generator myspace] [http://www.zip.dk/gaeste/bog.php3?id=25387 friend generator myspace] [http://www.zip.dk/gaeste/bog.php3?id=25386 custom friend generator myspace space] [http://www.zip.dk/gaeste/bog.php3?id=25385 myspace layout generator] [http://www.zip.dk/gaeste/bog.php3?id=25384 carolina college foundation north] [http://www.zip.dk/gaeste/bog.php3?id=25383 adoption dave foundation thomas] [http://www.zip.dk/gaeste/bog.php3?id=25382 foundation window workflow] [http://www.zip.dk/gaeste/bog.php3?id=25381 foundation hidradenitis suppurativa] [http://www.zip.dk/gaeste/bog.php3?id=25380 foundation indian southwest] [http://www.zip.dk/gaeste/bog.php3?id=25378 colorado foundation hines] [http://www.zip.dk/gaeste/bog.php3?id=25377 elk foundation mountain rocky] [http://www.zip.dk/gaeste/bog.php3?id=25376 dave foundation thomas] [http://www.zip.dk/gaeste/bog.php3?id=25375 concrete foundation raise repair] [http://www.zip.dk/gaeste/bog.php3?id=25374 360 box dvd hd x] [http://www.zip.dk/gaeste/bog.php3?id=25373 box collector dvd friend] [http://www.zip.dk/gaeste/bog.php3?id=25372 decorating home product] [http://www.zip.dk/gaeste/bog.php3?id=25371 cheap free shipping toy] [http://www.zip.dk/gaeste/bog.php3?id=25370 overseas carpentry jobs] [http://www.zip.dk/gaeste/bog.php3?id=25369 but left their card and failed to file out a report] [http://www.zip.dk/gaeste/bog.php3?id=25368 accessory card file] [http://www.zip.dk/gaeste/bog.php3?id=25367 180 buy hcl tablet tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25366 buy hcl.idilis.ro link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25365 buy cheap.k25.net link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25364 buy health.20mbweb.com link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25363 buy link online.int.tc tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25362 buy cheap.be.tc link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25361 buy link online.blog.com tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25360 buy link online.col.nu tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25359 buy link now.ql.st tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25358 buy href isuyen.blogdrive.com tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25357 buy search tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25356 buy link myblog.de tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25355 buy gem high quality stone] [http://www.zip.dk/gaeste/bog.php3?id=25354 buy gem precious stone] [http://www.zip.dk/gaeste/bog.php3?id=25353 grossmans building supply store] [http://www.zip.dk/gaeste/bog.php3?id=25352 building material tacoma] [http://www.zip.dk/gaeste/bog.php3?id=25351 building kempsville material] [http://www.zip.dk/gaeste/bog.php3?id=25350 building chattanooga material] [http://www.zip.dk/gaeste/bog.php3?id=25349 building las material vegas] [http://www.zip.dk/gaeste/bog.php3?id=25348 building detroit material] [http://www.zip.dk/gaeste/bog.php3?id=25347 building material pasadena] [http://www.zip.dk/gaeste/bog.php3?id=25346 building greenville material sc] [http://www.zip.dk/gaeste/bog.php3?id=25345 building jackson material] [http://www.zip.dk/gaeste/bog.php3?id=25344 building fort material worth] [http://www.zip.dk/gaeste/bog.php3?id=25343 building columbia material] [http://www.zip.dk/gaeste/bog.php3?id=25342 building diego material san] [http://www.zip.dk/gaeste/bog.php3?id=25341 building distributor material] [http://www.zip.dk/gaeste/bog.php3?id=25340 building cincinnati material] [http://www.zip.dk/gaeste/bog.php3?id=25339 building chicago material] [http://www.zip.dk/gaeste/bog.php3?id=25338 building dallas material] [http://www.zip.dk/gaeste/bog.php3?id=25337 building houston material] [http://www.zip.dk/gaeste/bog.php3?id=25336 texas custom build home] [http://www.zip.dk/gaeste/bog.php3?id=25335 a frame home to build] [http://www.zip.dk/gaeste/bog.php3?id=25334 build equity in home] [http://www.zip.dk/gaeste/bog.php3?id=25333 accessory bathroom exposition] [http://www.zip.dk/gaeste/bog.php3?id=25332 airsoft gun gun stun taser] [http://www.zip.dk/gaeste/bog.php3?id=25331 airsoft gun marui tokyo] [http://www.zip.dk/gaeste/bog.php3?id=25330 airline boston ticket] [http://www.zip.dk/gaeste/bog.php3?id=25329 airline italy ticket] [http://www.zip.dk/gaeste/bog.php3?id=25328 airline phoenix southwest ticket] [http://www.zip.dk/gaeste/bog.php3?id=25327 airline miami ticket] [http://www.zip.dk/gaeste/bog.php3?id=25326 airline pittsburgh ticket] [http://www.zip.dk/gaeste/bog.php3?id=25325 airline cheap edinburgh ticket uk] [http://www.zip.dk/gaeste/bog.php3?id=25324 airline ticket travel velocity] [http://www.zip.dk/gaeste/bog.php3?id=25323 airline cheap minute ticket] [http://www.zip.dk/gaeste/bog.php3?id=25322 airline international ticket] [http://www.zip.dk/gaeste/bog.php3?id=25321 airline blue jet ticket] [http://www.zip.dk/gaeste/bog.php3?id=25320 airline cheap really ticket] [http://www.zip.dk/gaeste/bog.php3?id=25319 airline orbitz ticket]  [http://www.zip.dk/gaeste/bog.php3?id=25415 8 borang permohonan spa] [http://www.zip.dk/gaeste/bog.php3?id=25414 med sona spa] [http://www.zip.dk/gaeste/bog.php3?id=25413 conair foot massaging productpage spa] [http://www.zip.dk/gaeste/bog.php3?id=25412 hotel pittsburgh spa] [http://www.zip.dk/gaeste/bog.php3?id=25411 hot spa springs] [http://www.zip.dk/gaeste/bog.php3?id=25410 day new spa york] [http://www.zip.dk/gaeste/bog.php3?id=25409 hot install replace spa tub] [http://www.zip.dk/gaeste/bog.php3?id=25408 hotel philadelphia spa] [http://www.zip.dk/gaeste/bog.php3?id=25407 day dc spa washington] [http://www.zip.dk/gaeste/bog.php3?id=25406 angeles day los spa] [http://www.zip.dk/gaeste/bog.php3?id=25405 certificate gift spa] [http://www.zip.dk/gaeste/bog.php3?id=25404 dealer pool spa] [http://www.zip.dk/gaeste/bog.php3?id=25403 boob bra ocean pool water] [http://www.zip.dk/gaeste/bog.php3?id=25402 clothes in pool] [http://www.zip.dk/gaeste/bog.php3?id=25401 play a free online pool game] [http://www.zip.dk/gaeste/bog.php3?id=25400 above build ground install pool swimming] [http://www.zip.dk/gaeste/bog.php3?id=25399 polyurethane reaction injection molding] [http://www.zip.dk/gaeste/bog.php3?id=25398 g5 laser logitech mouse] [http://www.zip.dk/gaeste/bog.php3?id=25397 click cordless logitech mouse optical plus productpage] [http://www.zip.dk/gaeste/bog.php3?id=25396 batt insulation poured rolled upgrade] [http://www.zip.dk/gaeste/bog.php3?id=25395 fiberglass insulation roll] [http://www.zip.dk/gaeste/bog.php3?id=25394 insulation plastic window] [http://www.zip.dk/gaeste/bog.php3?id=25393 cold heat insulation material whol] [http://www.zip.dk/gaeste/bog.php3?id=25392 high insulation temperature] [http://www.zip.dk/gaeste/bog.php3?id=25391 blowing insulation machine] [http://www.zip.dk/gaeste/bog.php3?id=25390 guitar string tighteners] [http://www.zip.dk/gaeste/bog.php3?id=25389 how to change electric guitar string] [http://www.zip.dk/gaeste/bog.php3?id=25388 box comment generator myspace] [http://www.zip.dk/gaeste/bog.php3?id=25387 friend generator myspace] [http://www.zip.dk/gaeste/bog.php3?id=25386 custom friend generator myspace space] [http://www.zip.dk/gaeste/bog.php3?id=25385 myspace layout generator] [http://www.zip.dk/gaeste/bog.php3?id=25384 carolina college foundation north] [http://www.zip.dk/gaeste/bog.php3?id=25383 adoption dave foundation thomas] [http://www.zip.dk/gaeste/bog.php3?id=25382 foundation window workflow] [http://www.zip.dk/gaeste/bog.php3?id=25381 foundation hidradenitis suppurativa] [http://www.zip.dk/gaeste/bog.php3?id=25380 foundation indian southwest] [http://www.zip.dk/gaeste/bog.php3?id=25378 colorado foundation hines] [http://www.zip.dk/gaeste/bog.php3?id=25377 elk foundation mountain rocky] [http://www.zip.dk/gaeste/bog.php3?id=25376 dave foundation thomas] [http://www.zip.dk/gaeste/bog.php3?id=25375 concrete foundation raise repair] [http://www.zip.dk/gaeste/bog.php3?id=25374 360 box dvd hd x] [http://www.zip.dk/gaeste/bog.php3?id=25373 box collector dvd friend] [http://www.zip.dk/gaeste/bog.php3?id=25372 decorating home product] [http://www.zip.dk/gaeste/bog.php3?id=25371 cheap free shipping toy] [http://www.zip.dk/gaeste/bog.php3?id=25370 overseas carpentry jobs] [http://www.zip.dk/gaeste/bog.php3?id=25369 but left their card and failed to file out a report] [http://www.zip.dk/gaeste/bog.php3?id=25368 accessory card file] [http://www.zip.dk/gaeste/bog.php3?id=25367 180 buy hcl tablet tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25366 buy hcl.idilis.ro link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25365 buy cheap.k25.net link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25364 buy health.20mbweb.com link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25363 buy link online.int.tc tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25362 buy cheap.be.tc link tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25361 buy link online.blog.com tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25360 buy link online.col.nu tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25359 buy link now.ql.st tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25358 buy href isuyen.blogdrive.com tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25357 buy search tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25356 buy link myblog.de tramadol] [http://www.zip.dk/gaeste/bog.php3?id=25355 buy gem high quality stone] [http://www.zip.dk/gaeste/bog.php3?id=25354 buy gem precious stone] [http://www.zip.dk/gaeste/bog.php3?id=25353 grossmans building supply store] [http://www.zip.dk/gaeste/bog.php3?id=25352 building material tacoma] [http://www.zip.dk/gaeste/bog.php3?id=25351 building kempsville material] [http://www.zip.dk/gaeste/bog.php3?id=25350 building chattanooga material] [http://www.zip.dk/gaeste/bog.php3?id=25349 building las material vegas] [http://www.zip.dk/gaeste/bog.php3?id=25348 building detroit material] [http://www.zip.dk/gaeste/bog.php3?id=25347 building material pasadena] [http://www.zip.dk/gaeste/bog.php3?id=25346 building greenville material sc] [http://www.zip.dk/gaeste/bog.php3?id=25345 building jackson material] [http://www.zip.dk/gaeste/bog.php3?id=25344 building fort material worth] [http://www.zip.dk/gaeste/bog.php3?id=25343 building columbia material] [http://www.zip.dk/gaeste/bog.php3?id=25342 building diego material san] [http://www.zip.dk/gaeste/bog.php3?id=25341 building distributor material] [http://www.zip.dk/gaeste/bog.php3?id=25340 building cincinnati material] [http://www.zip.dk/gaeste/bog.php3?id=25339 building chicago material] [http://www.zip.dk/gaeste/bog.php3?id=25338 building dallas material] [http://www.zip.dk/gaeste/bog.php3?id=25337 building houston material] [http://www.zip.dk/gaeste/bog.php3?id=25336 texas custom build home] [http://www.zip.dk/gaeste/bog.php3?id=25335 a frame home to build] [http://www.zip.dk/gaeste/bog.php3?id=25334 build equity in home] [http://www.zip.dk/gaeste/bog.php3?id=25333 accessory bathroom exposition] [http://www.zip.dk/gaeste/bog.php3?id=25332 airsoft gun gun stun taser] [http://www.zip.dk/gaeste/bog.php3?id=25331 airsoft gun marui tokyo] [http://www.zip.dk/gaeste/bog.php3?id=25330 airline boston ticket] [http://www.zip.dk/gaeste/bog.php3?id=25329 airline italy ticket] [http://www.zip.dk/gaeste/bog.php3?id=25328 airline phoenix southwest ticket] [http://www.zip.dk/gaeste/bog.php3?id=25327 airline miami ticket] [http://www.zip.dk/gaeste/bog.php3?id=25326 airline pittsburgh ticket] [http://www.zip.dk/gaeste/bog.php3?id=25325 airline cheap edinburgh ticket uk] [http://www.zip.dk/gaeste/bog.php3?id=25324 airline ticket travel velocity] [http://www.zip.dk/gaeste/bog.php3?id=25323 airline cheap minute ticket] [http://www.zip.dk/gaeste/bog.php3?id=25322 airline international ticket] [http://www.zip.dk/gaeste/bog.php3?id=25321 airline blue jet ticket] [http://www.zip.dk/gaeste/bog.php3?id=25320 airline cheap really ticket] [http://www.zip.dk/gaeste/bog.php3?id=25319 airline orbitz ticket]  [http://jkgff84plhy.com/ jkgff84plhy]  [http://jkgff84plhy.com/ jkgff84plhy] </div>
 

Latest revision as of 00:17, 31 January 2007

Exemple scripturi BASH

Scripturi care permit schimbarea rapida a MAC+IP

Raptor360 12:33, 8 June 2006 (EEST)

getmac

Primeste ca parametru un IP si returneaza MAC-ul acestuia sau "" daca nu exista in retea nodul cu pricina.

/usr/local/bin/getmac#!/bin/sh

if ! $IFDEVICE ; then

       IFDEVICE="eth0";

fi

mac=`arping -I $IFDEVICE $1 -c 3 | grep reply | cut -f2 -d\[ | cut -f1 -d\] | uniq` echo $mac

be

Primeste ca parametru un IP si schimba MAC-ul si IP-ul pentru un device.

/usr/local/bin/be#!/bin/bash

if ! $IFDEVICE ; then

       IFDEVICE="eth0"

fi

gip=`echo -e "$1\t"` echo -e " IP is $1." mac=`cat /etc/stored | grep "$gip" | cut -f2` echo -e "MAC is $mac." if $mac != "" ; then

       ifconfig $IFDEVICE down
       ifconfig $IFDEVICE hw ether $mac
       ifconfig $IFDEVICE $1 netmask 255.255.248.0 broadcast 10.10.17.255
       route add default gw 10.10.17.1
       # echo "nameserver 10.10.17.1" > /etc/resolv.conf

else

       echo "$1 has not an associated MAC."

fi

switchuser

Schimba MAC-ul si IP-ul aleator conform unuia stocat in /etc/stored folosind scripturile anterioare.

/usr/local/bin/switchuser#!/bin/bash

notfound=1 while $notfound -eq 1 ; do

       rip=`echo "$RANDOM % 252 + 3" | bc`
       for i in `seq $rip 254`; do
               randip="10.10.17.$i"
               gip=`echo -e "$randip\t"`
               if  grep "$gip" | cut -f2` != "" ; then
                       if `getmac $randip` == "" ; then
                               be $randip
                               exit 0
                               notfound=1
                       else
                               echo "IP $randip is already active."
                       fi
               else
                       echo "$randip has no MAC associated."
               fi
       done

done

Scripturile folosesc fisierul de configurare /etc/stored in care se adauga perechi de forma: IP\tMAC, e.g. 10.10.17.241 00:20:ED:95:2A:A1 10.10.17.242 4C:00:10:53:BF:A5 precum si variabila din enviroment IFDEVICE daca este definita. e.g. daca vrem sa schimbam ip-ul doar pentru device-ul eth1 atunci apelam la: # IFDEVICE=eth1 switchuser

Script care lanseaza in fundal o anumita comanda data ca parametru de intrare

Puteti lasa o comanda sa se execute in fundal fara ca ea sa fie intrerupta la iesirea dumneavoastra din sistem folosind urmatorul script pe care l-am numit silent. (output-ul nu este salvat, pentru aceasta puteti folosi nohup)

#!/bin/bash

echo "Executing \"$*\"" setsid bash -c $* 2>>/dev/null 1>>/dev/null < /dev/null &

Scriptul il puteti folosi de exemplu:

$ silent wget -c -t 0 www.bigfiles.com/ubuntu.iso

Script ce elimina zona asociata unui domeniu dat ca parametru de intrare

Puteţi elimina porţiunea din named.conf de la zone "nume.domeniu.dat.ca.parametru.de.intrare" { până la acolada închisă asociată acoladei deschise de mai sus.

Scriptul este:#!/bin/bash

  1. Bind zone remove script
  2. Copyright (C) 2005 Silvian Cretu <silvian86@yahoo.com>
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

if [ ! $# = 1 ]; then

   echo "Usage: $0 domain";
   echo "The path to named.conf is defined inside the script";
   		 else

pathToNamedDotConf=/etc/named.conf

x=$(grep -n "zone \"$1\" {" $pathToNamedDotConf | cut -f1 -d:) sed $x,/\}\;/d $pathToNamedDotConf > temp c=$(sed -n $x'p' < temp) if [ "x`echo $c | grep "zone"`" = "x" ] then sed $x' d' temp > $pathToNamedDotConf else cat temp > $pathToNamedDotConf fi rm -f temp exit fi

Cautarea unui fisier ce contine un anumit string

find /path -name "*" -exec grep -H "<string>" '{}' \; sau grep -Hr "<string>" /path/

Fireste, <string> poate fi atat un sir de caractere cat si orice fel de expresie regulata suportata de versiunea particulara de grep disponibila pe masina in cauza.
Deasemenea, pentru a cauta fara a face diferenta intre majuscule si minuscule, adaugati parametrul -i la grep.

Daca doriti ca in output-ul comenzii grep expresia cautata sa fie cautata sa fie evidentiata puteti folosi parametrul --color astfel: grep --color -Hr "<string>" /path/

Stergerea fisierelor backup

Asa cum stiti, prin traditie in *NIX, editoarele text fac o copie de siguranta fisierelor editate, copie de siguranta ce este denumita identic cu fisierul initial plus caracterul tilda (~). Ei bine... in cazul aplicatiilor web, acest backup mai mult dauneaza decat sa ajute. Nu ar fi prea placut sa aveti un index.php~ in DocumentRoot

find /path -name "*~" | xargs -n 20 rm -f

Probleme cu spatiul pe disc?

Nu stiti unde "vi s-a dus" spatiul de pe disc si e cam greu sa verificati fiecare director in parte?
Linia urmatoare va ajuta, facand totodata si o sortare.

du --max-depth=1 /path | sort -rn

Gasirea fisierelor duplicate intr-un director

Aveti prea multe mp3-uri si majoritatea sunt duplicate dar cu alt nume sau orice de genul folositi scriptul de mai jos:D Eventual adaugati si un -maxdepth 1 sa nu fie recursiv.

  1. !/bin/sh

if [ ! -d "$1" ]; then

 echo "Usage $0 <dir>"
 exit 1

fi find "$1" -type f -print0 | xargs -0 -n1 md5sum | sort --key=1,32 | uniq -w 32 -d --all-repeated=prepend \

                                    |cut -f3- -d' '|sed 's/^$/Fisiere identice:/'

Calcularea recordului de uptime

Scriptul urmator va trebui plasat in crontab astfel incat sa ruleze periodic, de exemplu, din ora in ora. El va afisa in fisierul $output (initial /var/log/uptimeRecord.log) output-ul comenzilor uptime si date (adica uptime-ul record si data la care a fost inregistrat).

#!/bin/bash

  1. Copyright (C) 2006 Silvian Cretu <silvian86@yahoo.com>
  2. This program is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License
  4. as published by the Free Software Foundation; either version 2
  5. of the License, or (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

output='/var/log/uptimeRecord.log'

function compareHrs {

       uptimeCurent=`uptime`
       if [ `echo $uptimeCurent | grep -c day` == '0' ]; then
  1. echo Uptime mai mic de o zi
               uptimeCurentOre=`uptime | awk '{print $3}'`
               uptimeRecordOre=`cat $output | head -1 | awk '{print $3}'`
       else
               uptimeCurentOre=`uptime | awk '{print $5}'`
               uptimeRecordOre=`cat $output | head -1 | awk '{print $5}'`
       fi
       if [ `expr length $uptimeCurentOre` \> `expr length $uptimeRecordOre` ]; then
  1. echo Nou record - Uptime curent mai mare cu cateva ore decat uptime-ul record 1
               uptime > $output
               date >> $output
       else
               if [ `expr length $uptimeCurentOre` == `expr length $uptimeRecordOre` ]; then
                       uptimeCurentOra=`echo $uptimeCurentOre | cut -d":" -f1`
                       uptimeRecordOra=`echo $uptimeRecordOre | cut -d":" -f1`
                       if [ $uptimeCurentOra -gt $uptimeRecordOra ]; then
  1. echo Nou record - Uptime curent mai mare cu cateva ore decat uptime-ul record 2
                               uptime > $output
                               date >> $output
                       fi
               fi
       fi

}

if [ -a $output ]; then

       uptimeCurent=`uptime`
       uptimeRecord=`cat $output | head -1`
       if [ `echo $uptimeCurent | grep -c day` == '0' ]; then
  1. echo Uptime mai mic de o zi
               if [ `echo $uptimeRecord | grep -c day` == '0' ]; then
  1. echo Uptime record mai mic de o zi, comparam orele
                       compareHrs
  1. else
  2. echo Uptime record mai mare ca uptime curent
               fi
       else
  1. echo Uptime mai mare de o zi
               if [ `echo $uptimeRecord | grep -c day` == '0' ]; then
  1. echo Uptime record mai mic de o zi
                       uptime > $output
                       date >> $output
               else
                       uptimeCurentZile=`uptime | awk '{print $3}'`
                       uptimeRecordZile=`cat $output | head -1 | awk '{print $3}'`
                       if [ $uptimeCurentZile -eq $uptimeRecordZile ]; then
  1. echo Uptime in zile egal
                               compareHrs
                       else
                               if [ $uptimeCurentZile -gt $uptimeRecordZile ]; then
  1. echo Record nou
                                       uptime > $output
                                       date >> $output
                               fi
                       fi
               fi
       fi

else

  1. echo Fisierul nu exista, deci trebuie creat. Recordul e uptime-ul curent
       uptime > $output
       date >> $output

fi

exit 0

Stergere directoare vechi de pe o partiţie pentru salvarea spaţiului

Scriptul următor poate fi plasat în cron şi rulat cam din oră în oră pentru a şterge directoare vechi. Un exemplu clasic este ştergerea jpeg-urilor generate de cameră de supraveghere conectată la un server Linux:

#!/bin/bash

  1. Copyright (C) 2005-2007 Silvian Cretu <silvian86@yahoo.com>
  2. This program is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License
  4. as published by the Free Software Foundation; either version 2
  5. of the License, or (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  1. Constante:

partitie=/var/www # partitia monitorizata procentMaxim="97%" # procentul maxim de ocupare acceptat pt partitia monitorizata X=1 # se vor sterge directoarele mai vechi de X zile director=/var/www/html/camera/events/2 # directorul din care se vor sterge subdirectoarele

  1. Cat de ocupata este partitia monitorizata (in procente):

procentOcupare=$(df -h | grep $partitie | awk '{print $5}')

if [[ "$procentMaxim" < "$procentOcupare" ]] || [ "$procentOcupare" == "100%" ]; then # trebuie sterse directoarele mai vechi de X zile find $director -type d -mtime +$X -exec rm -rf {} \; fi

exit