v-list-fs-directory 884 B

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