check_scratch 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. # Check for folders that do not match a username and files in /local/scratch/
  3. ########
  4. # created by Silva ()
  5. # last edit Silva (7-10-2017)
  6. #######
  7. path2scratch="/local/scratch/"
  8. # Search for files other than welcome file in the scratch dir
  9. find $path2scratch -maxdepth 1 -type f ! -name "WELCOME_TO_SCRATCH" -exec echo "ERR: Find file at level 0: {}" \;
  10. # Save all folders in scratch
  11. folders=( $(find $path2scratch -maxdepth 1 -mindepth 1 -type d | sed "s:$path2scratch::") )
  12. for fld in ${folders[@]}
  13. do
  14. # Search for folder name in usernames database
  15. user=$(finger -smp $fld 2>/dev/null | sed -e '1d' | awk '{print $1}' | uniq) ;
  16. if ! [ "$user" ]
  17. then
  18. echo "ERR: directory $fld doesn't match any user in db"
  19. fi
  20. # Check last access to folder
  21. lastaccess=$(stat --format "%X" "$path2scratch/$fld")
  22. years_sinceacc=$(echo $lastaccess $(date +%s) | awk '{t=($2-$1)} END{ print int(t/(365*24*60*60))}')
  23. if [[ $years_sinceacc -ge 1 ]]
  24. then
  25. echo "WARNING: Last acces to $fld is older than $years_sinceacc years"
  26. fi
  27. done