0

I am trying to make a command which will find all the files modified in past 24 hours and which are PHP only with a loop to look into each public_html directories and save the output into a HTML file so i can view daily.

 for i in `ls /var/cpanel/users`; 
 do find /home/$i/public_html -type f -ctime -1 -exec ls -ls {} \; > 
 /home/demo4/public_html/output.html;
 done;

But it is not working properly and giving output not correct.. here is the output which is only for 1 account, it should be for all accounts

0 -r-xr-xr-x 1 ziaengg ziaengg 0 Jan 12 15:16 /home/ziaengg/public_html/modules/mod_rsflashmatic/xml/rsflashmatic_93.xml 23320 -rw-r--r-- 1 ziaengg ziaengg 23851008 Jan 12 15:25 /home/ziaengg/public_html/error_log

Also i would like to learn how can i email the result to any specific id..

And what parameter should i add if i want to exclude any file containing the keyword cache. I am really new to this.

muru
  • 72,889
  • For mailing, try the mailx command: http://heirloom.sourceforge.net/mailx/mailx.1.html#30 – muru Jan 12 '15 at 14:22

2 Answers2

4

Try:

cd /var/cpanel/users &&
for i in *
do
    find "/home/$i/public_html" -type f ! -iname '*cache*' -ctime -1 -ls 
done > /home/demo4/public_html/output.html

Notes:

  • Use >> instead of >, otherwise each iteration overwrites the output of the last. Or redirect the output of the whole loop, in which case you can use >.
  • some find implementations have a -ls option which is quite like -exec ls -ld {} \;, so use it instead where available.
  • Use the ! operator to negate searches: ! -iname '*cache*'
  • if your find doesn't support the non-standard -iname predicate, use -name '*[cC][aA][cC][hH][eE]*' instead.
  • Since these are usernames, you could use for i in $(ls ..), but it is safer to use for i in *.
muru
  • 72,889
2

With zsh on a GNU system with uconv and recode:

{ echo '<html><head><meta charset="UTF-8"</head><body><pre>'
  users=(/var/cpanel/users/*(:t)) &&
    find /home/$^users/public_html -type f -ctime -1 ! -iname '*cache*' -ls |
    uconv --from-callback escape-c -f utf8 -t utf8 |
    recode u8..html
  echo "</pre></body></html>"
} > /home/demo4/public_html/output.html

(note however that recode doesn't support characters above U+FFFF)

You need those additional uconv/recode steps to avoid problems with filenames with < or & characters in their name or 8 bit byte values (here we assume file names are UTF-8 encoded (and for invalid characters, we display their byte values as \xAB)

  • this is something looks like pizza, i am learning how to make an egg right now :) – Amanullah Tanweer Jan 12 '15 at 21:29
  • @user38002, then why make a html file and not a txt file? Making proper txt is easier than making proper html. And if you don't do it properly, then you introduce vulnerabilities (like some form of XSS with filenames like <script>...). – Stéphane Chazelas Jan 12 '15 at 21:32
  • Since i am Web Developer i love HTML files and this is what i made http://demo4.inheritedarts.com/emailstats/ ... is this really vulnerable ? i will make txt file insted then and fetch it from php after it – Amanullah Tanweer Jan 12 '15 at 22:04