Cygwin .sh文件作为Windows Task Scheduler运行

问题描述 投票:2回答:1

使此Shell脚本在Windows Task Scheduler中运行时遇到问题。

#!/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.shtest.sh:第4行:grep:找不到命令

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

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

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

在Windows Scheduler中,我有操作:启动一个程序详细信息:C:\ cygwin64 \ bin \ bash.exe参数:test.sh开始于:C:\ cygwin64 \ bin

我想念什么吗?

windows shell cygwin
1个回答
6
投票

我知道了。

在Windows Task Scheduler中,我必须通过:

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

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

开始于:C:\ cygwin64 \ bin

© www.soinside.com 2019 - 2024. All rights reserved.