Interessante Linux Shell Scripts

Mal wieder auf der suche in den unendlichen weiten des WWW’s habe ich noch eine gute Webseite entdeckt die cyberciti.biz heisst.
Da findet ihr tonnenweise gute Shellscripts wovon ich euch nun ein paar vorstellen möchte.



Shell Script für das direkte hinzufügen von MySQL DB,User, PW und Host:
Kommando

./script.sh bar tom jerry ‘192.168.1.5|192.168.1.11’
#!/bin/bash
# A shell script to add mysql database, username and password.
# It can also grant remote access on fly while creating the database.
# ————————————————————————-
# Copyright © 2007 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# ————————————————————————-
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ————————————————————————-
# Last updated on Jan/09/2010
# ————————————————————————-
_db=“$1”
_user=“$2”
_pass=“$3”
_dbremotehost=“$4”
_dbrights=“$5”

## Path to mysql bins ##
mysql=“/usr/bin/mysql”
## Mysql root settings ##
_madminuser=‘root’
_madminpwd=‘MySQL-PassWord’
_mhost=‘localhost’

# make sure we get at least 3 args, else die
[[ $# -le 2 ]] && { echo “Usage: $0 ‘DB_Name’ ‘DB_USER’ ‘DB_PASSORD’ [‘remote1|remote2|remoteN’] [‘DB_RIGHTS’]“; exit 1; }

# fallback to ALL rights
[[ -z “${_dbrights}” ]] && _dbrights=“ALL”

# build mysql queries
_uamq=“${mysql} -u “${_madminuser}” -h “${_mhost}” -p’${_madminpwd}’ -e ‘CREATE DATABASE ${_db};‘”
_upermq1=“${mysql} -u “${_madminuser}” -h “${_mhost}” -p’${_madminpwd}’ -e \“GRANT ${_dbrights} ON ${_db}.* TO [email protected] IDENTIFIED BY ‘${_pass}‘;\“”

# run mysql queries
$_uamq
$_upermq1

# read remote host ip in a bash loop
# build queires to grant permission to all remote webserver or hosts via ip using the same username
IFS=‘|’
for i in ${_dbremotehost}
do
_upermq2=“${mysql} -u “${_madminuser}” -h “${_mhost}” -p’${_madminpwd}’ -e \“GRANT ${_dbrights} ON ${_db}.* TO ${_user}@${i} IDENTIFIED BY ‘${_pass}‘;\“”
$_upermq2
done


Shell Script der von einem Domainnamen Alle Information Preisgibt die man für eine genauere Analyse braucht (beispielsweise bei einem Angriff)
Kommando:
./script.sh cyberciti.biz bash.ch
#!/bin/bash
# A sample shell script to print domain ip address hosting information such as
# Location of server, city, ip address owner, country and network range.
# This is useful to track spammers or research purpose.
# ————————————————————————-
# Copyright © 2006 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# ————————————————————————-
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ————————————————————————-
# Last updated on Mar/05/2010
# ————————————————————————-

# Get all domains
_dom=$@

# Die if no domains are given
[ $# -eq 0 ] && { echo “Usage: $0 domain1.com domain2.com …“; exit 1; }
for d in $_dom
do
_ip=$(host $d | grep ‘has add’ | head -1 | awk ‘{ print $4}’)
[ “$_ip” == “” ] && { echo “Error: $d is not valid domain or dns error.“; continue; }
echo “Getting information for domain: $d [ $_ip ]…”
whois “$_ip” | egrep -w ‘OrgName:|City:|Country:|OriginAS:|NetRange:’
echo “”
done

comments powered by Disqus