Cygwin .sh文件作为Windows任务计划程序运行

时间:2013-10-10 01:57:57

标签: windows shell cygwin

Howdie do,

让这个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:第4行:找不到grep:command

test.sh:第4行:awk:未找到命令

test.sh:第7行:[::预期的整数表达式

我的问题是,如何让它与bash一起运行,以便它实际上知道grep和awk命令?

在Windows Scheduler中,我有一个Action:Start A Program 详细信息:C:\ cygwin64 \ bin \ bash.exe 参数:test.sh 开始于:C:\ cygwin64 \ bin

我错过了什么吗?

1 个答案:

答案 0 :(得分:6)

我明白了。

在Windows任务计划程序中,我必须传递:

程序/脚本:C:\ cygwin64 \ bin \ bash.exe

添加参数:-c -l test.sh

开始于:C:\ cygwin64 \ bin

相关问题