[英]Cygwin .sh file run as Windows Task Scheduler
让这个 shell 脚本在 Windows 任务调度程序中运行时遇到问题。
#!/bin/bash
# Script to ping the VPN server for testing
RESULT=$(ping 192.168.1.252 | grep "Lost" | awk {' print $10 '})
LOG=/home/admin/results.txt
if [ "$RESULT" -gt 0 ];then
echo "VPN 192.168.1.252 NOT pinging" >> $LOG
else
echo "VPN Online"
fi
当我在 cygwin 中运行它时,它运行没有问题,但是当我尝试从命令提示符运行它时,我得到以下信息:
C:\cygwin64\bin>bash test.sh test.sh: line 4: grep: command not found
test.sh:第 4 行:awk:找不到命令
test.sh:第 7 行:[: : 预期的整数表达式
我的问题是,如何让它与 bash 一起运行,以便它真正知道 grep 和 awk 命令?
在 Windows 调度程序中,我有操作:启动 A 程序详细信息:C:\cygwin64\bin\bash.exe 参数:test.sh 开始于:C:\cygwin64\bin
我错过了什么吗?
我想到了。
在 Windows 任务计划程序中,我必须通过:
程序/脚本:C:\cygwin64\bin\bash.exe
添加参数:-c -l test.sh
开始于:C:\cygwin64\bin
纠正吉米的发现:
添加参数:-c -l "c:/FileFolder/test.sh"
您不再需要 Start in 参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.