无法找出此Shell脚本错误:文件意外结束

时间:2019-01-17 15:08:59

标签: bash shell unix

几十年来一直写着shell脚本,但我无法发现这个脚本有什么问题...可以吗?

获取错误:./tasks.sh:第57行:语法错误:文件意外结束

不,它不是dosmode行尾样式。

#!/bin/sh

export TZ='US/Central'
export PATH="$PATH:$HOME/bin"

#### Function: die
die() { exit 0 ; }

#### Function: tasks dayname
tasks() { ls ${1}_* 2>/dev/null }

#### Function: runtasks task [task2]
runtasks() {
 for TASK
 do
  DT=$(date '+%Y-%m-%d')
  TM1=$(date '+%H:%M:%S')
  EPOCH=$(date '+%s')
  TSK=$($TASK)
  TM2=$(date '+%H:%M:%S')
  echo "$DT,$TM1,$TM2,$EPOCH,$TASK,$TSK"
 done
}

# DAILY PROCESSING:
TASKDIR=$HOME/.daily

cd $TASKDIR 2>/dev/null || die

exec 2>> 0daily.err

DAY=$(date +%a|tr '[A-Z]' '[a-z]')
DEF="$DAY all"
OUT=''

# args can be all or a day else just use today + all for the daily tasks to run:
TODO="${1:-${DEF}}"

for WORK in $TODO
do
  RAN=''
  TASKS=''
  case "$WORK" in
    sun|mon|tue|wed|thu|fri|sat|all)
       TASKS=$(tasks $WORK)
       RAN=$(runtasks $TASKS)
       if [ "$RAN" != "" ] ; then
         OUT="${OUT}${RAN}"
       fi
       ;;
    *) break ;;
  esac
done

test "$OUT" && echo "$OUT" >> 0daily.out

脚本的要点是通过每天一次的调度程序调用,在$ HOME / .daily中运行任何任务

例如:.daily / all_backup_machine.sh 或:.daily / mon_compact_mail_folders.sh

我想你让我流连忘返。

0 个答案:

没有答案