Using BATCH to call a BASH script on CygWin


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Using BATCH to call a BASH script on CygWin
# 1  
Old 03-24-2017
Using BATCH to call a BASH script on CygWin

I am trying to use a batch file to automatically execute a bash script with no luck this far.
The batch script looks like this:
Code:
 C:\Cygwin64\bin\bash test.sh

I have also tried this:
Code:
 C:\Cygwin64\bin\bash "C:\Cygwin64\bin\test.sh"

Needless to say that the windows box has Cygwin installed on it.
Any ideas/suggestions are very much appreciated!
# 2  
Old 03-25-2017
The syntax looks correct.

Please check :
Is the test.sh in unix file format ?
Is your PATH on Windows configured properly to include CYGWIN/bin at the end ?
CYGWIN being path where you installed cygwin default being c:\cygwin\bin


Hope that helps
Regards
Peasant.
# 3  
Old 03-25-2017
If CYGWIN is installed in c:\cygwin\bin and you're trying to run your script that is installed as c:\cygwin\bin\test.sh, is CYGWIN being confused by your test.sh and the CYGWIN test utility both being located in the same directory?

When CYGWIN is installed isn't bash set to run files with .sh as a file extension? If so, would trying to run test from Windows try to invoke c:\cygwin\bin\test or c:\cygwin\bin\test.sh?
# 4  
Old 03-25-2017
SOLVED!

I actually came to realized that in CygWin I must use gawk instead
So I decided to run gawk using CMD. Everything is fine but when I tried to read a variable from a file using a gawk script inside other gawk script I get a warning message.
This is the script I am using:
Code:
gawk -v "est=gawk '{ print $1}' C:\minimum.txt" '{ calc=( est / $2)*15 } {print $2, calc}' C:\cygwin64\User\Output.txt > C:\cygwin64\User\Output2.txt

This is the warning I am getting:
Code:
gawk: warning: escape sequence `\m' treated as plain `m'

I tried to escape the path using quotes, double quotes or backslashes with no luck:
Code:
gawk -v "est=gawk '{ print $1}' "C:\minimum.txt"" '{ calc=( est / $2)*15 } {print $2, calc}' C:\cygwin64\User\Output.txt > C:\cygwin64\User\Output2.txt

I just cannot figure it out. Is there any other way to read the variable from the file within gawk?
# 5  
Old 03-25-2017
The code that you have shown us doesn't make any sense to me.
  1. Please explain in English what you are trying to do.
  2. Please show us the contents of the file C:\minimum.txt.
  3. Please show us the contents of the file C:\cygwin64\User\Output.txt.
  4. Please show us the output you hope to produce in the file C:\cygwin64\User\Output2.txt.
# 6  
Old 03-26-2017
Don
Quote:
Please explain in English what you are trying to do.
I am calculating volumes based on concentrations. Here, I am "translating" a file that is being generated by one documentation system into a CSV file that will be understood by a robotic unit. The controllers are Windows based boxes (connected by a LAN cable). The idea is to have a BATCH file that will automatically translate and feed the CSV file into the computer controlling the robotic unit
Quote:
Please show us the contents of the file minimum.txt.
The minimum file will contain a number that will change from run to run -the user will not have access to that file. Something like this:
Code:
2.0

I am outputting that number using the following script:
Code:
gawk '{ print $1}' C:\minimum.txt"

I am using the above script to defince variable est
Code:
gawk -v "est=gawk '{ print $1}' C:\minimum.txt"

The rest of my code divides the data generated by the documentation system and multiplies it for a constant (15), printing the original concentration value and the calculated volume
Code:
'{ calc=( est / $2)*15 } {print $2, calc}' C:\cygwin64\User\Output.txt > C:\cygwin64\User\Output2.txt

The Output file contains hundreds of entries and looks like this:
Quote:
A1 4.58
B1 2.57
C1 5.56
D1 3.58
E1 3.22
F1 3.09
G1 3.27
H1 2.46
A2 2.55
B2 2.31
C2 3.85
D2 2.62
E2 2.76
F2 2.06
G2 2.69
The Output2 file should look like this:
Code:
4.58 6.55022
2.57 11.6732
5.56 5.39568
3.58 8.37989
3.22 9.31677
3.09 9.70874
3.27 9.17431
2.46 12.1951
2.55 11.7647
2.31 12.987
3.85 7.79221
2.62 11.4504
2.76 10.8696
2.06 14.5631
2.69 11.1524

PS. I could do it with not many issues in CygWin but using BATCH will be much easier. Fetching the variable from the minimum file and inputting it in my script handling the calculations is the last step. My batch files works like a charm when I enter the actual number:
Code:
gawk -v "est=2" '{ calc=( est / $2)*15 } {print $2, calc}' C:\cygwin64\User\Output.txt > C:\cygwin64\User\Output2.txt

I am restricted to what CMD allows me to do. I cannot use bash or any other unix approach for this particular task
Thanks in advance for any help tackling this issue
# 7  
Old 03-26-2017
It's been a while since I've run batch scripts, but I don't remember it having a command substitution construct like bash (and other POSIX shell conforming utilities) and there's no need to fire up two invocations of awk (or gawk) when awk is perfectly capable of reading two input files in one invocation. If batch processes single quotes and double quotes the same way the POSIX shell command language does, try:
Code:
gawk 'FNR == NR{est = $1 * 15; next}{print $2, est / $2}' C:\minimum.txt C:\cygwin64\User\Output.txt > C:\cygwin64\User\Output2.txt

Or, ff your input files are DOS format text files and you want the output to be a DOS format text file, you might need to get rid of <carriage-return> characters from the input lines and add them to the output:
Code:
gawk '{sub(/\r/, "")}FNR == NR{est = $1 * 15; next}{printf("%.2f %.6f\r\n", $2, est / $2)}' C:\minimum.txt C:\cygwin64\User\Output.txt > C:\cygwin64\User\Output2.txt

Neither of these have been tested at all, but should come close to what you need.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script (tar + md) on Cygwin

Hi everybody, First, I'm sorry for my bad english! I have the following situation: I have a Windows 2012 R2 with Cygwin installed. The Windows Server is used as a backup Server with Dell AppAssure installed. At the moment, AppAssure saves Backup Targets to a repository on his D. The... (9 Replies)
Discussion started by: fibra3000
9 Replies

2. Shell Programming and Scripting

Need help in batch renaming files with bash shell script.

I have some 50+ files in the following format : abcd_vish_running_ZEBRA_20140818.dat_08-14-2014_23:08:23 abcd_vish_running_ZEB-RA_20140818.dat_08-14-2014_23:08:35 abcd_vish_running_ZEB_RA_20140818.dat_08-14-2014_23:08:37 abcd_vish_running_RI-NG_20140818.dat_08-14-2014_23:08:42... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

3. Shell Programming and Scripting

Cygwin bash script to unmount and mount an XP partition

As stated, I am looking into keeping my backup drive unmounted in normal windows use. Partly this is to address threats like cryptolocker. Since one of my backup drives is an internal drive, it will not likely afford any protection from such a threat. I am thinking of adding code to my rsync script... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

4. Windows & DOS: Issues & Discussions

run cygwin bash script from notepad++

I'm using Notepad++ to edit my BASH scripts and using CYGWIN to run them from Windows7. In Notepad++ there is a 'Run' capability. How do I get this to run my scripts directly without having to enter the script name from the Cygwin command line? (3 Replies)
Discussion started by: millsy5
3 Replies

5. Shell Programming and Scripting

tftp batch mode within bash script

Hi, I put the necessary tftp commands into a batch file and I can run tftp by $ tftp < tftpbatchscript in bash command line and then successfully exit. Now, I want to put a line which does the same thing above. However, when I put this line into a bash script, the lines below this line... (1 Reply)
Discussion started by: yildiz.a
1 Replies

6. Shell Programming and Scripting

BASH: Script jams Cygwin to 100% CPU -

I'd like to streamline the code more than a bit to get it to run faster. There's a thread about this and related issues of mine on the Cygwin mailing-list, but I want to eliminate any chances it might just be inefficient/inelegant/crappy code. A previous run of the same script on both Cygwin and... (6 Replies)
Discussion started by: SilversleevesX
6 Replies

7. UNIX for Dummies Questions & Answers

Cygwin bash script and read command

Hello everyone, I am struggling a bit with a batch script that I need to run in cygwin. I work in winXP and I had to write some awk scripts to do some file manipulation, and now I would like to automate the process by just running a batch file so that my colleagues can use it easily. Now, the... (2 Replies)
Discussion started by: Teroc
2 Replies

8. Windows & DOS: Issues & Discussions

Problems with batch files for Cygwin/rxvt

I'm trying to write batch scripts of the kind that start a Cygwin session in rxvt from the desktop, with the added feature that the session starts in a folder other than $HOME. I want to do this for two folders I use often. According to the manpage, rxvt has a "-cd" command. Therefore, at first... (4 Replies)
Discussion started by: SilversleevesX
4 Replies

9. UNIX for Dummies Questions & Answers

How to use cygwin to run bash script

Hi, all, I try to run a quite simple bash script mytest.sh in cygwin, it's content is: #!/bin/bash echo "It is my first bash shell" there are three lines in the script. The second line is blank line. When I run it use command: bash c:/mytest.sh, ... (6 Replies)
Discussion started by: Jenny.palmy
6 Replies

10. Shell Programming and Scripting

bash - batch script for extracting one file from multiple tar files

so i have hundreds of files named history.20071112.tar (history.YYYYMMDD.tar) and im looking to extract one file out of each archive called status_YYYYMMDDHH:MM.lis here is what i have so far: for FILE in `cat dirlist` do tar xvf $FILE ./status_* done dirlist is a text... (4 Replies)
Discussion started by: kuliksco
4 Replies
Login or Register to Ask a Question