Posts

Showing posts with the label shell scripting

iptables check every hour

Always use full path i.e /sbin/iptables for setting iptables in crontab 0 * * * * /bin/sh /bum/iptables_check.sh #!/bin/bash # #Check if firewall is up ISUP=`/sbin/iptables -L -n | grep DROP` if [ -z "$ISUP" ] then echo "Firewall is down on `hostname`" | mail -s "Firewall Status" linux@drushti.in fi chmod 700 iptables_check.sh

shell scripting

Conditionals let us decide whether to perform an action or not, this decision is taken by evaluating an expression. Expressions An expression can be: String comparison, Numeric comparison, File operators and Logical operators and it is represented by [expression]: String Comparisons: --------------------------------- = compare if two strings are equal != compare if two strings are not equal -n evaluate if string length is greater than zero -z evaluate if string length is equal to zero = is equal to - if [ "$a"= "$b" ] == is equal to -f if [ "$a"=="$b" ] != is not equal to if [ "$a" !="$b" ] < is less then ,in ASCII alphabetical order if [["$a" < "$b"]] > is greater than, in ASCII alphabetical order if [[ "$a" > "$b"]] -z string is null, that is has zero length Examples: [ s1 = s2 ] (true if s1 same as s2, else false) [ s1 != s2 ] (true if s1 not s...