Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cywin bash script command not found when called from batch

Tags:

bash

cygwin

#!/bin/bash
echo "Testing"
cd "/cygdrive/x/Internal Communications/Riccardo/"
filename=htdocs-`date +%A`.tar.gz
tar cvzf $filename "/cygdrive/c/Program Files/Zend/Apache2/htdocs"

The above script is working when it is called inside cygwin console, but when I try to call it from a batch file I get "command not found" for date and tar command. I think that bash.exe does not have the PATH set up.

I need to run that script from that batch file because I want to add the script to the task scheduler.

like image 601
rtacconi Avatar asked Jul 29 '09 16:07

rtacconi


People also ask

How do I run a bash script in Cygwin?

into a CygWin terminal type the command ls /bin/bash.exe : it list the executable for bash. open a windows CMD and type the command dir C:\cygwin\bin\bash.exe : it list the executable for bash.

Does Cygwin use bash?

The Cygwin installation creates a Bash shell along with a UNIX environment by which you can compile and run UNIX-like programs. Using this one can even create an emulated X server on your windows box and run UNIX-like GUI software tools.


3 Answers

FWIW, Cygwin has cron.

Are you calling your script like this?

bash --login -i ./myscript.sh
like image 94
seth Avatar answered Sep 25 '22 21:09

seth


As has already been said, you need to add the Cygwin binaries to your path. To do so, right click on "My Computer", click "Properties", then "Advanced", then "Environment Variables".

Create a new environment variable with name "CYGWIN_HOME" and value "C:\cygwin" (or wherever you installed cygwin. The default location is "C:\cygwin\" so this should probably work for you).

Then edit the environment variable named "PATH", and tack on the following to the end:

;%CYGWIN_HOME%\bin;%CYGWIN_HOME%\sbin;%CYGWIN_HOME%\usr\bin;%CYGWIN_HOME%\usr\sbin;%CYGWIN_HOME%\usr\local\bin;%CYGWIN_HOME%\usr\local\sbin

Close your command prompt, then reopen it. The cygwin binaries should now be available. You can double-check this by typing "which bash". It should report the location of your bash executable.

like image 20
Michael Aaron Safyan Avatar answered Sep 24 '22 21:09

Michael Aaron Safyan


Put your cygwin bin directory (likely C:\cygwin\bin) on your PATH environment variable.

This would also give you the benefit of being able to use commands like tar, ls, rm, etc. from a regular console windows and not just a Cygwin console.

like image 40
matt b Avatar answered Sep 23 '22 21:09

matt b