diff --git a/shell/task.sh b/shell/task.sh index e0666b34..2349c344 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -77,12 +77,6 @@ run_nohup() { ## 正常运行单个脚本,$1:传入参数 run_normal() { local first_param=$1 - cd $dir_scripts - local relative_path="${first_param%/*}" - if [[ ! -z ${relative_path} ]]; then - cd ${relative_path} - first_param=${first_param/$relative_path\//} - fi define_program "$first_param" if [[ $first_param == *.js ]]; then if [[ $# -eq 1 ]]; then @@ -92,6 +86,9 @@ run_normal() { log_time=$(date "+%Y-%m-%d-%H-%M-%S") log_dir_tmp="${first_param##*/}" + log_dir_tmp_path="${first_param%%/*}" + log_dir_tmp_path="${log_dir_tmp_path##*/}" + [[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}" log_dir="$dir_log/${log_dir_tmp%%.*}" log_path="$log_dir/$log_time.log" cmd="&>> $log_path" @@ -107,6 +104,12 @@ run_normal() { [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" "$begin_timestamp" eval . $file_task_before "$@" $cmd + cd $dir_scripts + local relative_path="${first_param%/*}" + if [[ ! -z ${relative_path} ]]; then + cd ${relative_path} + first_param=${first_param/$relative_path\//} + fi eval timeout -k 10s $command_timeout_time $which_program $first_param $cmd eval . $file_task_after "$@" $cmd @@ -141,15 +144,12 @@ run_concurrent() { local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g') - cd $dir_scripts - local relative_path="${first_param%/*}" - if [[ ! -z ${relative_path} ]]; then - cd ${relative_path} - first_param=${first_param/$relative_path\//} - fi define_program "$first_param" log_time=$(date "+%Y-%m-%d-%H-%M-%S") log_dir_tmp="${first_param##*/}" + log_dir_tmp_path="${first_param%%/*}" + log_dir_tmp_path="${log_dir_tmp_path##*/}" + [[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}" log_dir="$dir_log/${log_dir_tmp%%.*}" log_path="$log_dir/$log_time.log" cmd="&>> $log_path" @@ -171,6 +171,13 @@ run_concurrent() { local envs=$(eval echo "\$${env_param}") local array=($(echo $envs | sed 's/&/ /g')) single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") + + cd $dir_scripts + local relative_path="${first_param%/*}" + if [[ ! -z ${relative_path} ]]; then + cd ${relative_path} + first_param=${first_param/$relative_path\//} + fi for i in "${!array[@]}"; do export ${env_param}=${array[i]} single_log_path="$log_dir/${single_log_time}_$((i + 1)).log" @@ -201,15 +208,12 @@ run_designated() { exit 1 fi - cd $dir_scripts - local relative_path="${file_param%/*}" - if [[ ! -z ${relative_path} ]]; then - cd ${relative_path} - file_param=${file_param/$relative_path\//} - fi define_program "$file_param" log_time=$(date "+%Y-%m-%d-%H-%M-%S") log_dir_tmp="${file_param##*/}" + log_dir_tmp_path="${file_param%%/*}" + log_dir_tmp_path="${log_dir_tmp_path##*/}" + [[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}" log_dir="$dir_log/${log_dir_tmp%%.*}" log_path="$log_dir/$log_time.log" cmd="&>> $log_path" @@ -242,6 +246,12 @@ run_designated() { [[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr} + cd $dir_scripts + local relative_path="${file_param%/*}" + if [[ ! -z ${relative_path} ]]; then + cd ${relative_path} + file_param=${file_param/$relative_path\//} + fi eval timeout -k 10s $command_timeout_time $which_program $file_param $cmd eval . $file_task_after "$@" $cmd diff --git a/shell/update.sh b/shell/update.sh index da504c0e..2f902947 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -391,6 +391,16 @@ gen_list_repo() { files=$(echo "$files" | egrep -v $blackword) fi if [[ $dependence ]]; then + cd ${dir_scripts} + depInScripts=$(eval $cmd | sed 's/^..//' | egrep -v $uniq_path | egrep $dependence) + for dep in ${depInScripts}; do + file_path=$(dirname $dep) + [[ ! $file_path =~ "/" ]] && file_path="" + make_dir "${dir_scripts}/${uniq_path}/${file_path#*/}" + cp -f $dep "${dir_scripts}/${uniq_path}/${file_path#*/}" + done + + cd ${repo_path} results=$(eval $cmd | sed 's/^..//' | egrep $dependence) for _file in ${results}; do file_path=$(dirname $_file)