KfWiki : ShellScript

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Revision [1556]

Most recent edit made on 2008-03-26 08:34:59 by WikiAdmin

Deletions:
header1 header2
cell1 cell2




Revision [1555]

Edited on 2008-03-26 08:34:35 by WikiAdmin

Additions:
""<table border=1 class="data">


Deletions:
""<table border=1>




Revision [1554]

Edited on 2008-03-26 08:34:07 by WikiAdmin

Additions:
header1 header2
cell1 cell2


Deletions:
|| ^a || Go to beginning of line||
||^a, alt-l|| Go to beginning of line, and change all letters to lower case||
||alt-c|| Change line to lower case||
||^e|| Go to end of line||
||^r|| Recall last command in history, starting with charcters provided||
||^k|| Delete line||
||^w|| Delete word||
||^y|| Undo deletion||
||^l|| Clear screen||




Revision [1553]

Edited on 2008-03-26 08:33:45 by WikiAdmin

Additions:
""<table border=1>
<tr><td>^r</td><td> Go to end of line</td></tr>
<tr><td>^k</td><td> Delete line</td></tr>
<tr><td>^w</td><td> Delete word</td></tr>
<tr><td>^y</td><td>Undo deletion</td></tr>
<tr><td>^l</td><td> Clear screen</td></tr>


Deletions:
""<table>




Revision [1552]

Edited on 2008-03-26 08:32:14 by WikiAdmin

Additions:
^aGo to beginning of line
^a, alt-lGo to beginning of line, and change all letters to lower case
alt-cChange line to lower case
^e Go to end of line




Revision [1548]

Edited on 2008-03-26 08:21:04 by WikiAdmin

Deletions:
header1 header2
cell1 cell2




Revision [1547]

Edited on 2008-03-26 08:20:30 by WikiAdmin

Additions:
header1 header2
cell1 cell2




Revision [1546]

Edited on 2008-03-26 08:19:27 by WikiAdmin

Additions:
|| ^a || Go to beginning of line||
eval "$1=\"xxx\""
echo ${PATH[$i]}
find ${PATH[$i]} ! -name "*.zip" -mtime +31 | xargs zip -m ${PATH[$i]}/logs-$DATESTR.zip
IP=`host "$1" | awk '{print $4}' | sed s/found\:/NOT_FOUND/g`
if [ ${#IP} -lt 2 ]; then
# no record found
echo -n "NOT_FOUND"
else
echo -n $IP
fi
MX=`host -tmx "$1" | grep handled | grep -v datapipe | awk '{print $7}' | sed '$!N;s/\n/\g'`
if [ ${#MX} -lt 2 ]; then
# no MX record found
echo NONE
else
# get IP address for each MX record
MXIP=`host "$MX" | awk '{print $4}' | sed s/found\:/NOT_FOUND/g`
echo "$MX ($MXIP)"
fi
d=`echo $f | awk 'BEGIN {FS=","} {print $1}'`
echo -n $f
getip "$d"
echo -n ","
getmx "$d"


Deletions:
||^a|| Go to beginning of line||
eval "$1=\"xxx\""
echo ${PATH[$i]}
find ${PATH[$i]} ! -name "*.zip" -mtime +31 | xargs zip -m ${PATH[$i]}/logs-$DATESTR.zip
IP=`host "$1" | awk '{print $4}' | sed s/found\:/NOT_FOUND/g`
if [ ${#IP} -lt 2 ]; then
# no record found
echo -n "NOT_FOUND"
else
echo -n $IP
fi
MX=`host -tmx "$1" | grep handled | grep -v datapipe | awk '{print $7}' | sed '$!N;s/\n/\g'`
if [ ${#MX} -lt 2 ]; then
# no MX record found
echo NONE
else
# get IP address for each MX record
MXIP=`host "$MX" | awk '{print $4}' | sed s/found\:/NOT_FOUND/g`
echo "$MX ($MXIP)"
fi
d=`echo $f | awk 'BEGIN {FS=","} {print $1}'`
echo -n $f
getip "$d"
echo -n ","
getmx "$d"




Revision [1474]

Edited on 2008-03-10 03:22:11 by WikiAdmin

Additions:
Regular Expressions




Revision [1399]

Edited on 2008-02-12 03:10:03 by WikiAdmin

Additions:

Function and variables



Deletions:

Function and variables





Revision [1398]

Edited on 2008-02-12 03:09:35 by WikiAdmin

Additions:

Compare floating point numbers

LOAD=`uptime | cut -d: -f5 | cut -d, -f1`
LIMIT=5.0
echo $LOAD
if [ `expr $LOAD \> $LIMIT` -eq 1 ]; then
# do your thing

real example 1



Deletions:

rael example 1





Revision [1397]

Edited on 2008-02-12 01:46:56 by WikiAdmin

Additions:

if [ ${#IP} -lt 2 ]; then
# no record found
echo -n "NOT_FOUND"
else
echo -n $IP
fi
MX=`host -tmx "$1" | grep handled | grep -v datapipe | awk '{print $7}' | sed '$!N;s/\n/\g'`
# no MX record found
# get IP address for each MX record
MXIP=`host "$MX" | awk '{print $4}' | sed s/found\:/NOT_FOUND/g`
echo "$MX ($MXIP)"
done%%


Deletions:

echo -n $IP
MX=`host -tmx "$1" | grep handled | awk '{print $7}' | sed '$!N;s/\n/\g'`
echo $MX




Revision [1396]

Edited on 2008-02-12 01:38:44 by WikiAdmin

Additions:

Function and variables

function run() {
eval "$1=\"xxx\""
VAR=1
run VAR
echo $VAR




Revision [1395]

Edited on 2008-02-12 01:19:34 by WikiAdmin

Additions:

MX=`host -tmx "$1" | grep handled | awk '{print $7}' | sed '$!N;s/\n/\g'`


Deletions:

MX=`host -tmx "$1" | grep handled | grep -v datapipe | awk '{print $7}' | sed '$!N;s/\n/\g'`




Revision [1394]

Edited on 2008-02-12 01:19:10 by WikiAdmin

Additions:

rael example 1

#!/bin/bash
# script to get IP and MX record for a list of domains
# column definition
# COL1: domain name
# COL2: apache virtual host domain
# COL3: IP address of A record
# COL4: MX record(s)
function getip() {
IP=`host "$1" | awk '{print $4}' | sed s/found\:/NOT_FOUND/g`
echo -n $IP
}
function getmx() {
MX=`host -tmx "$1" | grep handled | grep -v datapipe | awk '{print $7}' | sed '$!N;s/\n/\g'`
if [ ${#MX} -lt 2 ]; then
echo NONE
else
echo $MX
fi
}
for f in `cat domains_step2.csv`
d=`echo $f | awk 'BEGIN {FS=","} {print $1}'`
echo -n $f
getip "$d"
echo -n ","
getmx "$d"




Revision [1140]

Edited on 2007-11-07 22:52:42 by WikiAdmin

Additions:

Compiling shell scripts to binary executables

http://www.datsi.fi.upm.es/~frosal/
Use the command shc -f script_file_name




Revision [1121]

Edited on 2007-11-02 01:24:36 by WikiAdmin

Additions:

bash array and loops

#!/usr/local/bin/bash
PATH[0]=/home/sites/1/
PATH[1]=/home/sites/2/
PATH[2]=/home/sites/3/
PATH[3]=/home/sites/4/
PATH[4]=/home/sites/5/
arrsize=${#PATH[@]}
DATESTR=`/bin/date +%Y-%m`
for ((i=0;i<$arrsize;i)); do
echo ${PATH[$i]}
find ${PATH[$i]} ! -name "*.zip" -mtime +31 | xargs zip -m ${PATH[$i]}/logs-$DATESTR.zip
exit 0




Revision [956]

Edited on 2007-09-10 19:52:11 by WikiAdmin

Additions:

if then else

if [ ! -f blah.txt ]; then
echo "File does not exist."
echo "File already exist."
fi




Revision [433]

Edited on 2007-05-02 02:13:31 by WikiAdmin

Additions:

bash prompt

Reference: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html
PS1="\u@\h \W> "




Revision [339]

The oldest known version of this page was edited on 2007-04-23 23:52:01 by WikiAdmin
HomePage » ShellScript

bash shortcuts

||^a|| Go to beginning of line||
||^a, alt-l|| Go to beginning of line, and change all letters to lower case||
||alt-c|| Change line to lower case||
||^e|| Go to end of line||
||^r|| Recall last command in history, starting with charcters provided||
||^k|| Delete line||
||^w|| Delete word||
||^y|| Undo deletion||
||^l|| Clear screen||

More at http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html

Case switch

case "$1" in
start)
 do start;
;;

stop)
 do stop;
;;

*)
 echo usage;
;; 
esac


Read input, if then else

echo "Please enter an address to forward to."
echo "To disable forward, type DISABLE"
read fw
if [ $fw == "DISABLE" ]; 
then
 echo "Disable mail forward done."
 rm -Rf ~/.forward
elif [ $fw == "disable" ]; 
 then
 echo "Disable mail forward done."
 rm -Rf ~/.forward
else
 echo "Activating mail forward to $fw"
 echo $fw > ~/.forward
fi
echo "Done."

for loop

TASKS=`ls -1 /scp/backup.jobs/*.sh`
for tt in $TASKS
do
	   eval $tt & LASTJOB=$!
	   wait $LASTJOB
done


Text parsing

sed -n "s/.*ok.*:.*:25 .*:\(.*\)::.*/\1/gp" /var/log/smtpd/current
cut -f5 -d: /var/log/smtpd/current | grep .
egrep -R ok /var/log/smtpd/current |awk '{print $6}'|sed -e 's/:/ /g'| cut -f2 -d' '
awk 'BEGIN {FS=":" } /ok/ {print $5}' /var/log/smtpd/current
fgrep ok /var/log/smtpd/current | cut -f5 -d: fgrep ok /var/log/smtpd/current | cut -f5 -d:
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 1.0586 seconds