simple script to correct wordpress permissions

Script


#!/bin/bash
loc=$1

echo "finding and correcting directory perms"
find "$loc" -type d -exec chmod 755 {} \;
#copy htaccess to wp-root
cp /root/wp-root-htaccess "$loc/.htaccess"
#copy uploads htaccess to uploads
cp /root/wp-uploads-htaccess "$loc/wp-content/uploads/.htaccess"
#echo "$loc"
echo "finding and correcting file perms"
find "$loc" -type f -exec chmod 644 {} \;

wp-root-htaccess


#protect wp-config
<files wp-config.php>
order allow,deny
deny from all
</files>

wp-uploads-htaccess


# Kill PHP Execution
<Files ~ "\.ph(?:p[345]?|t|tml)$">
   deny from all
</Files>

BASH script unsplit for linux and mac

#!/bin/bash
#  Script.sh
#
#  Created by Marc Levine on 5/2/12.

FILES=*
for f in $FILES 
do
  
  # take action on each file. $f store current file name
	filename=$(basename $f)
	extension=${filename##*.}
	filename=${filename%.*}
	e2=${filename##*.}
	if [ "$extension" != "par2" ] && [ -f "$f" ] && [ "$e2" == "rar" ]
	then

	#echo "Processing $filename "
	cat $f >> $filename
	fi
done

Bash script to replace a string within a file

#!/bin/bash
# command line arguments are 1 search string and 2 the replacement
# handy for replacing ip addresses in host files
# example
# strreplace.sh 192.168.0.2 10.0.0.4
for f in *
do
  echo "sed -i 's/$1/$2/g' $f" #let us know what we are about to screw up
  sed -i "s/$1/$2/g $f" #making it happen
done

BASH while loop

#!/bin/bash
# create while loop that starts at x and ends at y
# good for creating folders

if [ $# -eq 2 ]; then #if no arguments then prompt for one<!--?prettify linenums=true?-->
  x=$1
  y=$2
else
  echo -n "Where to begin:"
  read x
  echo -n "Where to end:"
  read y
fi

while [ $x -le $y ]
do
#action
# do something here
 echo "mkdir IS4560_Week$x"
##
  ((x++)) #increment x
done
echo "All done"

BASH script to lookup hostname on ip address

This script will check the hostnames on a block of IP addresses and randomly change DNS servers.


#!/bin/bash
# Marc Levine

#

if [ $# -eq 1 ]; then
IPRange=$1
echo -n "Please enter your log file name: "
read logfile
elif [ $# -eq 2 ]; then
    IPRange=$1
    logfile=$2
else
        echo "Please enter the IP range in slash notation ex:10.0.0.0/24"
        echo -n "CIDR Notation: " #the echo -n will write without a newline
        read IPRange
        echo -n "Please enter your log file name: "
        read logfile
fi
echo "Please sit back and relalx while this script runs"

function randDNS {
    case $1 in
        1)
            dns="8.8.8.8"
        ;;
        2)
            dns="8.8.4.4"
        ;;
        3)
            dns="209.244.0.4"

        ;;
        4)
            dns="209.244.0.3"

        ;;
    esac

}

#check hosts to see if they are live using nmap

ipString=`nmap $IPRange -n -sP | grep report | awk '{print $5}'`

read -a ipArray <<<$ipString

for ipHost in "${ipArray[@]}"
do
echo "Checking IP Address:" $ipHost

#generate random number to change dns server
rand=`echo $RANDOM % 4 + 1 | bc`
randDNS $rand
#echo dig @$dns +short -x  $ipHost
hostName=`dig @$dns +short -x  $ipHost`
unset -v dns
#output to file
echo "$ipHost,$hostName" >> "$logfile"
done