Home > Cpanel/WHM, Scripts > Script to Monitor file creation under all cpanel users documentroot

Script to Monitor file creation under all cpanel users documentroot


SITUATION: Customer wants to get the list of all newly created files under all cpanel users documentroot(/home/*/public_html).


ASSUMPTIONS: The ‘inotifywait’ command is installed. This command comes with the inotify-tools package.


SOLUTION: The following script spawns multiple ‘inotifywait’ processes into background, with each of these processes recursively monitoring and recording file creation events in each cpanel users documentroot. Newly created files under each users home directory are saved in location “/root/monitor/” with the filenames as each users name.

Save the script as “/etc/init.d/inotifywaitd” and grant execute permission to this script.





if [ $# != 1 ];then
   echo "Usage: /etc/init.d/inotifywaitd {start|stop}"
   exit 1

if [ ! -d ${DESTDIR} ];then
   mkdir ${DESTDIR}

case $1 in


      for i in `ls -d /home/*/public_html`
         user=$(echo "${i}"|cut -d\/ -f3)
         ${INOTIFY_CMD} -m -r -e create --format '%f' ${i} > ${DESTDIR}/${user}&


   stop) pkill inotifywait ;;

   *) echo "Usage: /etc/init.d/inotifywaitd {start|stop}" ;;



ERRORS: Sometime you may get the following error while running this script,

Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.

To resolve this issue, increase the filesystem inotify maximum user watches system variable as follows,

1) Get the current value of max_user_watches,

# sysctl -e fs.inotify.max_user_watches
fs.inotify.max_user_watches = 524288

2) Open up /etc/sysctl.conf and set value of “fs.inotify.max_user_watches” higher than 524288.

fs.inotify.max_user_watches = 924288

3) Reload sysctl configuration,

# sysctl -p /etc/sysctl.conf
Categories: Cpanel/WHM, Scripts
  1. beatriscoles
    July 10, 2013 at 2:54 pm

    Everyone loves what you guys
    are usually up too. This sort
    of clever work and exposure!

    Keep up the very good works guys I’ve you guys to our blogroll.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: