Personal tools

Difference between revisions of "Scripturi BASH"

From linux360

Jump to: navigation, search
(Added primary category binding and corrected secondary category spelling)
Line 46: Line 46:
 
  exit
 
  exit
 
  fi</pre>
 
  fi</pre>
 +
 +
=== Cautarea unui fisier ce contine un anumit string ===
 +
 +
<pre>find /path -name "*" -exec grep -H "string"  '{}' \;</pre>
 +
 +
Bineinteles, in loc de "string" puteti pune o expresie regulara.<br />
 +
Deasemenea, pentru o cautare ''case insensitive'', adaugati parametrul '''-i''' la ''grep''.
 +
 +
=== Stergerea fisierelor backup ===
 +
 +
Asa cum stiti, multe editoare text fac backup la fisierele editate. 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''
 +
 +
<pre>find /path -name "*~" -exec rm -f '{}' \;</pre>
  
 
[[Category:Collection]]
 
[[Category:Collection]]
 
[[Category:Programming]]
 
[[Category:Programming]]

Revision as of 09:34, 28 November 2005

Exemple scripturi BASH

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

# Bind zone remove script
#
# Copyright (C) 2005 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. 

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</pre>

Cautarea unui fisier ce contine un anumit string

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

Bineinteles, in loc de "string" puteti pune o expresie regulara.
Deasemenea, pentru o cautare case insensitive, adaugati parametrul -i la grep.

Stergerea fisierelor backup

Asa cum stiti, multe editoare text fac backup la fisierele editate. 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 "*~" -exec rm -f '{}' \;