Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin .sh file run as Windows Task Scheduler

Having issues getting this shell script to run in 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

When I run it in cygwin, it runs with no issue, but when I attempt to run it from command prompt, I get the following:

C:\cygwin64\bin>bash test.sh test.sh: line 4: grep: command not found

test.sh: line 4: awk: command not found

test.sh: line 7: [: : integer expression expected

My question is, how do I get it to run with bash instead so that it actually knows the grep and awk commands?

In Windows Scheduler, I have Action: Start A Program Details: C:\cygwin64\bin\bash.exe Argument: test.sh Start in: C:\cygwin64\bin

Am I missing something?

like image 784
Jimmy Avatar asked Oct 10 '13 01:10

Jimmy


1 Answers

I figured it out.

In the Windows Task Scheduler, I had to pass:

Program/script: C:\cygwin64\bin\bash.exe

Add arguments: -c -l test.sh

Start in: C:\cygwin64\bin

like image 108
Jimmy Avatar answered Oct 26 '22 21:10

Jimmy