v_list_sys_cron 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. # info: listing user cron
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. format=${2-shell}
  9. # Importing variables
  10. source $VESTA/conf/vars.conf
  11. source $V_FUNC/shared.func
  12. # Json function
  13. json_list_cron() {
  14. # Print top bracket
  15. echo '{'
  16. # Count fields
  17. fileds_count=$(echo $fields| wc -w )
  18. # Reading file line by line
  19. while read line; do
  20. # New delimeter
  21. IFS=$'\n'
  22. # Assing key=value pair
  23. eval $line
  24. # Closing bracket if there already was output
  25. if [ -n "$data" ]; then
  26. echo -e ' },'
  27. fi
  28. i=1
  29. IFS=' '
  30. for field in $fields; do
  31. eval value=\"$field\"
  32. value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
  33. if [ $i -eq 1 ]; then
  34. # Printing parrent
  35. (( ++i))
  36. echo -e "\t\"$value\": {"
  37. else
  38. # Printing child
  39. if [ $i -lt $fileds_count ]; then
  40. (( ++i))
  41. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  42. else
  43. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  44. data=1
  45. fi
  46. fi
  47. done
  48. done < $conf
  49. # Closing bracket if there was output
  50. if [ -n "$data" ]; then
  51. echo -e ' }'
  52. fi
  53. # Printing bottom bracket
  54. echo -e '}'
  55. }
  56. # Shell function
  57. shell_list_cron() {
  58. if [ -z "$nohead" ] ; then
  59. # Print brief info
  60. echo "${fields//$/}"
  61. for a in $fields; do
  62. echo -e "------ \c"
  63. done
  64. echo
  65. fi
  66. # Reading file line by line
  67. while read line ; do
  68. # Assing key=value pair
  69. eval $line
  70. # Print result
  71. eval echo "$fields" | sed -e "s/%quote%/'/g"
  72. done < $conf
  73. }
  74. #----------------------------------------------------------#
  75. # Verifications #
  76. #----------------------------------------------------------#
  77. # Checking args
  78. check_args '1' "$#" 'user [format]'
  79. # Checking argument format
  80. format_validation 'user'
  81. # Checking user
  82. is_user_valid
  83. #----------------------------------------------------------#
  84. # Action #
  85. #----------------------------------------------------------#
  86. # Defining config
  87. conf=$V_USERS/$user/cron.conf
  88. # Defining fileds to select
  89. fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $SUSPEND $DATE'
  90. # Listing domains
  91. case $format in
  92. json) json_list_cron ;;
  93. plain) nohead=1;
  94. fields="\"\$JOB\" \"\$SUSPEND\" \"\$MIN\" \"\$HOUR\" \"\$DAY\""
  95. fields="$fields \"\$MONTH\" \"\$WDAY\" \"\$CMD\"";
  96. shell_list_cron ;;
  97. shell) fields='$JOB~$SUSPEND~$MIN~$HOUR~$DAY~$MONTH~$WDAY~$CMD';
  98. shell_list_cron |column -t -s '~';;
  99. *) check_args '1' '0' 'user [format]' ;;
  100. esac
  101. #----------------------------------------------------------#
  102. # Vesta #
  103. #----------------------------------------------------------#
  104. exit