【问题标题】:Cygwin .sh file run as Windows Task SchedulerCygwin .sh 文件作为 Windows 任务计划程序运行
【发布时间】:2013-10-10 01:57:57
【问题描述】:

在 Windows 任务调度程序中运行此 shell 脚本时遇到问题。

#!/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:找不到命令

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

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

我的问题是,如何让它使用 bash 运行,以便它真正知道 grep 和 awk 命令?

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

我错过了什么吗?

【问题讨论】:

    标签: windows shell cygwin


    【解决方案1】:

    我想通了。

    在 Windows 任务计划程序中,我不得不通过:

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

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

    开始于:C:\cygwin64\bin

    【讨论】:

    • 您好,也许您可​​以帮我解决我遇到的类似问题here
    • 更具体地说,如何在任务调度程序中添加参数?我以C:\cygwin\bin\bash.exe -l /cygdrive/c/path/where/the/file/is/filename.sh 的身份运行以下内容并且我已经开始:C:\cygwin\bin
    【解决方案2】:

    纠正 Jimmy 的发现:

    添加参数:-c -l "c:/FileFolder/test.sh"

    您不再需要 Start in 参数。

    【讨论】:

      猜你喜欢
      • 2010-09-22
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      相关资源
      最近更新 更多