Batch script calls a Bash script but output file does not populate - bash

I have a batch script that looks like this
# echo off
c:/cygwin/bin/bash -li each_sec_extract.bash c:/iperfprocess/sprint/file1.txt > c:/iperfprocess/sprintbashed/file1.txt each_sec_extract.bash c:/iperfprocess/sprint/file2.txt > c:/iperfprocess/sprintbashed/file2.txt
When i run this as is, the CYGWIN bash terminal pops up and I can observe the script producing the output I want on the screen, however, when I go to the directory where the file should be located (c:/iperfprocess/sprintbashed/), I am greeted by an empty text file. When i enter instructions from the CMD line manually, I receive the same result. However, when I run the instruction directly from CYGWIN, it works flawlessly. The part that frustrates me the most, this script used to work fine, then I started getting SED: permission denied errors which forced me to run bash.exe in administrative mode.
Any ideas about what might be happening or what a solution may be? Thank you in advance for any and all help provided.

Is this any different?
#echo off
c:/cygwin/bin/bash -li each_sec_extract.bash c:/iperfprocess/sprint/file1.txt > c:/iperfprocess/sprintbashed/file1.txt
c:/cygwin/bin/bash -li each_sec_extract.bash c:/iperfprocess/sprint/file2.txt > c:/iperfprocess/sprintbashed/file2.txt

The SED: Permission error was the underlying cause of the empty output files that was experienced. Running bash in administrative privileges was only a work around that didn't fix the actual problem. For some reason, sed.exe became corrupt. The solution was comprised of downloading UnxUtils from http://sourceforge.net/projects/unxutils/?source=dlp and replacing the sed.exe found from CYGWIN/bin/ and replacing it with the one in the UnxUtils zip file.
I ran my script after these steps and everything worked perfectly as it did prior to the issue.

Related

Trying to run file in Mac Terminal

I type the name of the file into the Terminal as just "set.bat" but get:.
-bash: run: command not found
I also fail to understand how this question fails to meet stack overflow's quality standards without this extra paragraph, so if someone could enlighten me about this also I would be much obliged.
First you have to make sure that you are in the same folder of the file to run, then you issue:
$ ./filetoexecute
mind the ./, you'll have to write it because current directory is (almost never) in the path.
Additionally, .bat are Windows batch scripts, Bash will not understand them. You will have to look for a .sh (usual extension) or extensionless script.

how can i run rouge Summarization on windows?

I installed Strawberry Perl to run the rouge program in Windows. But when I want to run my program, I receive an error message that you can see on the image:
The system can't find the path specified.
My code is attempting to run "ROUGE-1.5.5.pl" but i think the system can't find this file. So I think maybe I don't initialize the path correctly?
I change my code to :
#!/usr/bin/perl
use Cwd;
$curdir=getcwd;
$ROUGE="..\ROUGE-1.5.5.pl";
chdir("sample-test");
$cmd="$ROUGE -e ..\data -c 95 -2 -1 -U -r 1000 -n 4 -w 1.2 -a DUC2002-ROUGE.in.26.spl.xml > ..\sample-output\output.out";
print $cmd,"\n";
system($cmd);
chdir($curdir);
and i receive this error:
Missing braces on \o{} at C:\runROUGE-test.pl line 7, near "$ROUGE" Execution of C:\runROUGE-test.pl aborted due to compilation errors.
As per the screen shot, you are attempting to run \ROUGE-1.5.5.pl where you probably want it without the spurious backslash (or with ..\ROUGE-1.5.5.pl if the parent directory is not on your PATH).
Similarly, you probably want the output in sample-output\output.out, or even just output.out, not \sample-output\output.out unless you specifically have a folder C:\sample-output for this purpose.
The backslash is significant; it is the absolute path to the root (of the current drive, on Windows). ..\ is the relative path to the parent folder.
Why are you writing a Perl script to run a Perl script, though? Either a simple batch file, or copy/pasting the command directly at the DOS prompt would seem like a less roundabout solution.
The problem is that when you are outputting the contents of the program to the file output.out in folder sample-output, the sample-output folder does not exist.
Command Prompt will not create the folders for you, only the files. Try creating a directory first called "sample-output" (In your drive root) such that the path resolves to something like C:\sample-output and run it again.
If the same problem results, try using an absolute path such as C:\sample-output\output.out instead.

How do I run .sh or .bat files from Terminal?

I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!

Problem setting up github repository, touch not recognized in CMD

When I get to the step:
touch README
I get the error
'touch' is not recognized as an internal or external command, operable program or batch file.
What does this mean?
I'm in Win 7 Home Premium command prompt.
Make sure you're working in git bash, not cmd.
The touch command updates the last-modified timestamp of the file to the current time, or if the file doesn't already exist, creates an empty file with the given name. This command does not exist (by default) in Windows, which is the reason you get that error message.
To get past this step, you can create a file called README in whatever way you feel most comfortable with. For example, you could use notepad.exe if you have no better alternative available.
Use this code in CMD and then touch your file
npm install touch-cli -g

Why can't Cygwin CVS read the CVS password file in a Ruby/Perl script?

On the Windows command line and cygwin bash I can execute the following without problems:
cvs login
cvs -Q log -N -rVersion_01_00
A ruby script in the same directory contains the following:
`cvs login`;
`cvs -Q log -N -rVersion_01_00`;
When I execute the ruby script on the Windows command line I get the following error:
cvs log: warning: failed to open /cygdrive/c/Documents and Settings/za100744/.cvspass for reading: No such file or directory
If I run the script in a cygwin bash shell I get the same output I would as when I type in the commands manually.
I have no idea as to what is going wrong. The path generated by the Ruby script is wrong since it is a cygwin path but it works correctly directly on the command line. I use cvs that came as part of cygwin:
which cvs
cvs is an external : C:\cygwin\bin\cvs.exe
Ruby is the one-click installer version:
which ruby
/cygdrive/c/Ruby/bin/ruby
It seems like cvs under Ruby can not resolve /cygdrive/c to c: but works OK from the cmdline.
Perl gives me exactly the same problem.
my $str = "cvs -Q log -N -r$cvs_tag|";
open(CVS_STATUS, $str) or die "\n##ERROR##";
It looks like either CVS can't create the file, or your path is wrong. Does the file .cvspass exist? If not, this page suggests you try creating an empty .cvspass file and then run your command. e.g. do
touch ~/.cvspass
If this doesn't help, then the problem is probably path related. There are a few possibilities; $HOME not set correctly, your home dir not matching what's in \etc\passwd, etc. See this tutorial for some troubleshooting steps that should help pin down the problem.
Using a windows native compiled CVS solves the problem. It is not ideal since I have to send a cvs executable with the script for users that has cygwin CVS but its better than nothing.
We had several problems with unix-, mixed- and windows-style paths in cygwin based perl scripts and built-in tools such as rsync. E.g. rsync can't handle wind-style paths. Use the tool "cygpath.exe" to adjust them correctly. Maybe it's the cause.

Resources