pwned

I wrote the below BASH function today. It’s good because it performs super well compared to the alternative commands (which are commented out below above the new commands):

own() {

  echo "Taking ownership..."
  #chown -R jj5:jj5 .
  find . \! -user jj5 -or \! -group jj5 -execdir chown jj5:jj5  "{}" \;
  [ "$?" = 0 ] || { echo "Could not take ownership in '$PWD'."; exit 1; }

  echo "Fixing directory permissions..."
  #find . -type d -execdir chmod u+rwx "{}" \;
  find . -type d -and \( \! -perm /u=r -or \! -perm /u=w -or \! -perm /u=x \) -execdir chmod u+rwx "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix directory permissions in '$PWD'."; exit 1; }

  echo "Fixing file permissions..."
  #find . -type f -execdir chmod u+rw "{}" \;
  find . -type f -and \( \! -perm /u=r -or \! -perm /u=w \) -execdir chmod u+rw "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix file permissions in '$PWD'."; exit 1; }

}

The basic premise is don’t do work which doesn’t need to be done!

Archive processing

Processed: /data/archive
Processing started: 2017-05-02 13:29:32
Processing completed: 2017-05-03 11:09:08
Processing time: 21.66h
Processed 2,151,351 directories.
Processed 13,138,509 files at 168 files/sec.
Found 43,139 symlinks.
Average number of files per directory is 6.11.
Created 10,278,937 hard links.
You have 2,859,572 unique files.
Your percentage of unique files is 21.76%.

fs.inotify.max_user_watches

I had an error tailing my web logs, like this:

==> test.jj5.net-error.log <==
tail: inotify resources exhausted
tail: inotify cannot be used, reverting to polling

I found tail: “inotify resources exhausted” and/or “inotify cannot be used, reverting to polling: Too many open files” which said to edit /etc/sysctl.conf with:

#
# 2017-05-03 jj5 - SEE: tail inotify resources exhausted:
# https://nefaria.com/2014/08/tail-inotify-resources-exhausted/
#
fs.inotify.max_user_watches=1048576

Then to apply the new settings:

# sysctl -p