v-search-fs-object 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. # info: search file or directory
  3. # options: USER OBJECT [PATH]
  4. #
  5. # The function search files and directories on the file system
  6. user=$1
  7. object=$2
  8. path=$3
  9. # Checking arguments
  10. if [ -z "$object" ]; then
  11. echo "Usage: USER OBJECT [PATH]"
  12. exit 1
  13. fi
  14. # Checking vesta user
  15. if [ ! -e "$VESTA/data/users/$user" ]; then
  16. echo "Error: vesta user $user doesn't exist"
  17. exit 3
  18. fi
  19. # Checking user homedir
  20. homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
  21. if [ -z $homedir ]; then
  22. echo "Error: user home directory doesn't exist"
  23. exit 12
  24. fi
  25. # Checking path
  26. if [ ! -z "$path" ]; then
  27. rpath=$(readlink -f "$path")
  28. if [ -z "$(echo $rpath |grep $homedir)" ]; then
  29. echo "Error: invalid path $dst_dir"
  30. exit 2
  31. fi
  32. else
  33. path=$homedir
  34. fi
  35. # Listing directory
  36. sudo -u $user find "$path" -name "$object" \
  37. -printf "%y|%m|%TY-%Tm-%Td|%TH:%TM|%u|%g|%s|%P\n" 2>/dev/null
  38. # -printf "%y|%m|%TY-%Tm-%Td|%TH:%TM:%TS|%u|%g|%s|%P\n" 2>/dev/null
  39. # Exiting
  40. exit $?