cron web pages

This commit is contained in:
Serghey Rodin 2012-06-22 15:40:29 +03:00
commit 2c237a82dd
11 changed files with 361 additions and 10 deletions

View file

@ -43,14 +43,14 @@ is_object_valid 'cron' 'JOB' "$job"
# Concatenating cron string
command=$(echo $command | sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month WDAY='$wday'"
str="$v_str' CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
# Deleting old job
sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
# Adding new
echo "$v_str" >> $USER_DATA/cron.conf
echo "$str" >> $USER_DATA/cron.conf
# Sorting jobs by id
sort_cron_jobs

91
bin/v_list_cron_job Executable file
View file

@ -0,0 +1,91 @@
#!/bin/bash
# info: list cron job
# options: user job [format]
#
# The function of obtaining cron job settings.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
job=$2
format=${3-shell}
# Includes
source $VESTA/func/main.sh
# Json function
json_list_job() {
i=1
fileds_count=$(echo "$fields" | wc -w)
line=$(grep "JOB='$job'" $conf)
echo '{'
eval $line
for field in $fields; do
eval value=$field
value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
if [ "$i" -eq 1 ]; then
echo -e "\t\"$value\": {"
else
if [ "$fileds_count" -eq "$i" ]; then
echo -e "\t\t\"${field//$/}\": \"$value\""
else
echo -e "\t\t\"${field//$/}\": \"$value\","
fi
fi
(( ++i))
done
if [ -n "$value" ]; then
echo -e ' }'
fi
echo -e "}"
}
# Shell function
shell_list_job() {
line=$(grep "JOB='$job'" $conf)
eval $line
for field in $fields; do
eval key="$field"
if [ -z "$key" ]; then
key=NULL
fi
echo "${field//$/}: $key "
done
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'user job [format]'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config and fields to select
conf=$USER_DATA/cron.conf
fields="\$JOB \$MIN \$HOUR \$DAY \$MONTH \$WDAY \$CMD \$SUSPENDED"
fields="$fields \$TIME \$DATE"
# Listing domains
case $format in
json) json_list_job ;;
plain) nohead=1; shell_list_job ;;
shell) shell_list_job |column -t ;;
*) check_args '2' '0' 'user job [format]'
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -83,7 +83,7 @@ is_object_valid 'user' 'USER' "$user"
conf=$USER_DATA/cron.conf
# Defining fileds to select
fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $SUSPENDED $TIME $DATE'
fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $JOB $SUSPENDED $TIME $DATE'
# Listing domains
case $format in