Dec 20

shell script to scan for any files changes and email it

ssh Comments Off on shell script to scan for any files changes and email it

Hi it has been along time since my last blog, i found this usefull script on this forum http://forums.asmallorange.com/topic/13649-shell-script-to-monitor-file-changes/. I just want to share it 🙂

just go to your shell and create scan.sh files

# vim scan.sh

and type this

####################################################################################################################

#!/bin/bash

#Directory to search
myDir=/home/username/public_html

#Set frequency of command in minutes, this should match how often you run the cron job
myFrequency=’-30′

#email address for mailing the results
myEmail=email@address.com

#Create datestamp for subject line
#This makes each subject line unique to prevent message collapsing in Gmail
myDate=`date +%y-%m-%d`
myTime=`date +%H:%M`

#Test if files have been edited
fileCount=`find $myDir -mmin $myFrequency -type f | wc -l`
if [ $fileCount -gt 0 ]
then
#Write the subject line and set correct form of the word “files” (singular or plural)
if [ $fileCount -eq 1 ]
then
mySubject=”Attention! $fileCount File Modified on $myDate at $myTime”
else
mySubject=”Attention! $fileCount Files Modified on $myDate at $myTime”
fi

#execute find command and email the results
find $myDir -mmin $myFrequency -type f | mail -s “$mySubject” $myEmail
#else nothing happens
fi

####################################################################################################################

then save it chmod 755 and run it (./scan.sh)

or you can create crontab to run every 30 minute

# crontab -e

*/30 * * * * /root/scan.sh

Mar 17

Bash ShortCuts

ssh Comments Off on Bash ShortCuts

Url Referer :

http://hsukumar.wordpress.com/2008/05/30/bash-short-cuts-hotkeys/

Ctrl + A

Go to the beginning of the line you are currently typing on

Ctrl + E

Go to the end of the line you are currently typing on

Ctrl + L

Clears the Screen, similar to the clear command

Ctrl + U

Clears the line before the cursor position. If you are at the end of the line, clears the entire line.

Ctrl + H

Same as backspace

Ctrl + R

Let’s you search through previously used commands

Ctrl + C

Kill whatever you are running

Ctrl + D

Exit the current shell

Ctrl + Z

Puts whatever you are running into a suspended background process. fg restores it.

Ctrl + W

Delete the word before the cursor

Ctrl + K

Clear the line after the cursor

Ctrl + T

Swap the last two characters before the cursor

Esc + T

Swap the last two words before the cursor

Alt + F

Move cursor forward one word on the current line

Alt + B

Move cursor backward one word on the current line

Tab

Auto-complete files and folder names

command to find files with permission 777

find / -perm 000777 -print | more -> to search the whole directory

find . -perm 000777 -print | more -> to search the current directory