Posts

Showing posts from December 19, 2013

Recursive searching via grep and sed

echo "Enter string to be placed" read NEWSTRING echo "===================================" echo "string to be replaced is $OLDSTRING" echo "string to be placed is $NEWSTRING  " echo "===================================" oldstr=$OLDSTRING #string to be replaced newstr=$NEWSTRING #new string to be placed echo "Enter folder path where we will find the string" read FOLDERPATH ### grep oldstring and output it in grep_output.txt    STEP1 grep -rl $oldstr $FOLDERPATH > grep_output.txt ### since there might be spaces or special characters on filenames, use sed to enclose them with quote and output in  sed_output.txt  STEP2 #for i in `cat grep_output.txt` #do sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" grep_output.txt  > sed_output.txt #done for i in `cat grep_output.txt` do sed -i "s/$oldstr/$newstr/g" $i > sed_output_new_old_string.txt done ## NOTE ## # 2013 latest ## STEP 2 Seems not wo

Bash create notification using du -h --max-depth

Created this simple script to email disk space usage. #!/bin/bash ## Email directory list if over quota BASE2=/home/vmail/mazaredo.com ## Check whole directory summary BASE=/home/vmail #50GB THRESHOLD=52428800 # out=$(du -s $BASE | cut -f1) # if [ $out -gt $THRESHOLD ] then  echo $out  du -h --max-depth=1 $BASE2 | mail -s "DISK USAGE EXCEEDED" postmaster@example.com else  echo "quota not reached" fi