IF 문에 나열된 명령 중 하나를 수행하지 못하는 셸 스크립트에서 작은 문제가 1 개 있습니다.예약 된 작업으로 실행했을 때 UNIX 셸 스크립트가 실행되지 않습니다.
터미널 창을 열고 전체 스크립트를 \ 붙여 넣으면 스크립트는 100 % 작동합니다.
당신은 단지 그것을 호출하여 스크립트를 실행하는 경우, 모든 작동 당신이 맨 아래에 볼이 라인을 제외하고 :
는 에코 $ NEWID> $ FileID에
환경은 GitBASH를 실행하는 Windows Server 2012입니다. (그게 C :/파일 경로를 설명 할 것입니다)
"스크립트"로 실행했을 때만 스크립트가 그 코드를 터미널에 복사하여 붙여 넣는 것에 비해 왜 스크립트가 그 1 작업을 수행하지 못하는지에 대한 아이디어가 있습니까?
다음은 전체 스크립트입니다. 감사합니다
# Clean directory
cd C:/Scripts/Shoretel_Export/
rm -f C:/Scripts/Shoretel_Export/output/*.csv
# <---- Define: Date variables (not all dates used but available if needed \ just modify the wget string) ----> #
twoDaysAgo=$(date +%Y-%m-%d -d '2 days ago')
yesterday=$(date +%Y-%m-%d -d 'yesterday')
today=$(date +%Y-%m-%d)
tomorrow=$(date +%Y-%m-%d -d 'tomorrow')
# <---- Define: Date timestamp variables for file naming ----> #
stampTwoDaysAgo=$(date +%m-%d-%Y -d '2 days ago')
stampTomorrow=$(date +%m-%d-%Y -d 'tomorrow')
# <---- Define: Credentials variable ----> #
account="--http-user=APIuser --http-password=APIpassword"
# <---- Define: Export output directory variable ----> #
sourceFile="C:/Scripts/Shoretel_Export/output/currentLastID.csv"
output=$"C:/Scripts/Shoretel_Export/output/"${stampTwoDaysAgo}"_"${stampTomorrow}".csv"
tempIDsource=$"C:/Scripts/Shoretel_Export/output/archive/"${stampTwoDaysAgo}"_"${stampTomorrow}".csv"
# <---- Define: Export lastID variable ----> #
callID=$(awk -F'","|^"|"$' 'BEGIN { max=0 } $1 > max { max=$1 } END {print max}' "C:/Scripts/Shoretel_Export/output/ID/ID.txt")
# <---- Execute WGET function to export Shoretel calls from the specified date range ----> #
wget --auth-no-challenge --no-check-certificate --output-document=${output} "https://portal.shoretelsky.com/DataExport/CDRData?startDate=${twoDaysAgo}&endDate=${tomorrow}&lastId=${callID}" ${account}
# Perform empty file validation, if file is 0 kb the script will terminate and retry
if [ -s "$output" ]
then
echo "File is not empty continue to next IF statement"
else
./retry.sh
fi
#### At this point we should have a valid file 1 kb or larger. If the export contains 0 new records the script will terminate and the previous callID will remain ####
# Define tempID to check for invalid or empty ID field
tempID=$(awk -F'","|^"|"$' 'BEGIN { max=0 } $18 > max { max=$18 } END {print max}' $output)
# Define ID paramaters and rename files
fileID="C:/Scripts/Shoretel_Export/output/ID/ID.txt"
if [ "$tempID" -gt "$callID" ]
then
cp $output C:/Scripts/Shoretel_Export/output/archive/
mv $output $sourceFile
newID=$(awk -F'","|^"|"$' 'BEGIN { max=0 } $18 > max { max=$18 } END {print max}' $tempIDsource)
echo $newID > $fileID
echo "Export and Timestamp complete"
else
echo "Export contains 0 new call records \ the script will now terminate"
fi
당신이 콘솔에서 실행할 때 사용하는 동일한 사용자를 사용하여 예약 된 작업으로 실행해야합니다. 또는'System' 사용자 (또는 예약 된 작업을 실행하는 모든 사용자가 Windows 시스템을 가지고 있지 않음)가 파일을 작성하는 데 필요한 권한을 가지고 있는지 확인하십시오. – axiac
Windows 작업에서 문제가 있다는 것을 알고있었습니다. 나는 그것이 어떻게 작동하는지 보여주기 위해 질문을 업데이트 할 것이다. 의견을 보내 주셔서 감사합니다! – CWB