- How to run batch file in linux
- How to run process from batch script
- Linux run command from file in batches
- GNU xargs
- Other xargs
- How to debug xargs ?
- Run python scripts in a batch on Linux?
- Invoking windows batch file from Linux
- Do batch files work on linux?
- What is batch file in Linux?
- Can you run BAT files on Ubuntu?
- Does cmd work in Linux?
- What files run on Linux?
- How to run .bat(Batch) Files on Linux (Ubuntu)
- Why is permission denied Linux?
- Can you run EXE files on Linux?
- Is Windows a Linux terminal?
- Is Windows Terminal like Linux?
- Is CMD a terminal?
- What are .sh files in Linux?
- What is the Linux equivalent of a batch file?
- How do I run a .sh file in Linux?
- Can I run Windows .bat files in Ubuntu?
- 2 Answers 2
- How do I create a batch file and run it? [duplicate]
- 3 Answers 3
How to run batch file in linux
If the windows box has a web server, you could write a CGI, and trigger it using wget or cURL. Solution 3: Our build process currently goes the other way: a windows sever kicks off things on the Linux server using plink (part of PuTTY). Depending on how precise your timing needs are, you might be able to have an «at» job on the windows box that runs periodically (every 5 minutes?) and runs if it sees that a particular file exists, deleting the file.
How to run process from batch script
Debian uses systemd to manage processes. You should, therefore, use the systemd’s commands to stop and start rsyslogd .
If you are using really old versions of Debian (so old that you should upgrade), it may be possible that sys V is still used. In that case, there is a file under /etc/init.d which is called rc.rsyslog or something comparable (use ls /etc/init.d to find the exact name). In that case, it would be
sudo /etc/init.d/rc.rsyslog stop
sudo /etc/init.d/rc.rsyslog start
Or it may be, that your systemd -package may be broken. In that case, the package can be re-installed:
apt-get --reinstall install systemd
If you want to do both, use
systemctl restart rsyslog
How do I run .sh or .bat files from Terminal?, 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 …
Linux run command from file in batches
GNU xargs
Other xargs
How to debug xargs ?
I would suggest use your favorite programming language to debug. Mine is Ruby, for example:
node -e 'console.log(process.argv)'
Put the above commands between xargs and the command you want to execute, for example:
xargs -n1 -P100 ruby -e 'p ARGV' bash -c < input.txt
["bash", "-c", "-v"] ["bash", "-c", "curl"] ["bash", "-c", "-XPOST"] ["bash", "-c", "-H"] ["bash", "-c", "https://httpbin.org/post"] ["bash", "-c", "-v"] ["bash", "-c", "-d"] ["bash", "-c", "Content-type:application/json"] ["bash", "-c", "curl"] ["bash", "-c", ""] ["bash", "-c", ""] ["bash", "-c", "-H"] ["bash", "-c", "Content-type:application/json"] ["bash", "-c", "-XPOST"] ["bash", "-c", "-d"] ["bash", "-c", "https://httpbin.org/post"] ["bash", "-c", "curl"] ["bash", "-c", "-v"] ["bash", "-c", "-XPOST"] ["bash", "-c", "-H"] ["bash", "-c", "Content-type:application/json"] ["bash", "-c", "-d"] ["bash", "-c", ""] ["bash", "-c", "https://httpbin.org/post"]z
xargs -d '\n' -n1 -P100 ruby -e 'pp ARGV' sh -c < input.txt
["sh", "-c", "curl -v -XPOST -H \"Content-type:application/json\" -d '' http://localhost:8080/v1/SomeEndPoint"] ["sh", "-c", "curl -v -XPOST -H \"Content-type:application/json\" -d '' http://localhost:8080/v1/SomeEndPoint"] ["sh", "-c", "curl -v -XPOST -H \"Content-type:application/json\" -d '' http://localhost:8080/v1/SomeEndPoint"]
If each line is a fully constructed command, xargs is the wrong tool.
sed -n 1,100p inputFile | while read line; do eval "$line"; done
sed -n 1,100p inputFile | while read line; do echo "$line" | sh; done
Certainly not the most elegant solution, but it could work:
input_file=test.sh batch_size=100 nlines=$(wc -l $input_file | cut -f 1 -d ' ') for i in $(seq 1 $batch_size $nlines); do for j in $(seq $i $((i+batch_size))); do line="$(sed -n $p $input_file)" eval "$line" & done wait done
It takes batches of n lines and executes them individually in the background with eval . After each batch, it waits for each background process to terminate ( wait ).
Windows - Run .bat in Linux environment, On Linux Terminal type wine cmd After that windows cmd will be played on your terminal. Go to the folder where your .bat file is located and type …
Run python scripts in a batch on Linux?
#!/bin/sh # This file is called ~/script.sh python script1.py python script2.py
Make the script executable.
Linux - How to write a batch file for running commands in, Under Actions, click New, leave Action set to "Start a program" and browse to the copy_myfile.bat script created in step 1. Click OK. Click OK and the …
Invoking windows batch file from Linux
You could install an ssh server in the windows box (Cygwin has one), then from linux do something like:
ssh user@windows-box c:/path/to/batch.cmd
and that should launch your application in the windows box.
The most direct way is probably to install an ssh server on the windows box. Cygwin includes an ssh server.
Depending on how precise your timing needs are, you might be able to have an "at" job on the windows box that runs periodically (every 5 minutes?) and runs if it sees that a particular file exists, deleting the file. Then you could use Samba/smbclient to create the file. You would need to turn on filesharing on the windows box for this to work.
If the windows box has a web server, you could write a CGI, and trigger it using wget or cURL.
Our build process currently goes the other way: a windows sever kicks off things on the Linux server using plink (part of PuTTY). You might be able to set something similar up.
Command line - Can I run Windows .bat files in Ubuntu?, Change to the directory containing your Windows batch file and run it by entering its name. Or, you can switch to the directory containing your batch …
Do batch files work on linux?
Unfortunately, many of the answers such people receive state that batch scripts cannot run on Linux. However, Linux users can indeed run batch files. Also, Windows batch files can be run on Windows like a native shell script.
What is batch file in Linux?
A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. . Unix-like operating systems, such as Linux, have a similar, but more flexible, type of file called a shell script.
Can you run BAT files on Ubuntu?
bat file, it will open in gedit>Tools>External Tools>Run command>in the popped up box type 'wineconsole cmd' (without inverted commas)>OK. 5. A Wine console terminal will pop up, in it type 'start yourfilename. bat' and hit enter.
Does cmd work in Linux?
Most of us think that Linux has terminal and we can use a command-line interface only in Linux but it is just a myth. There is a PowerShell and a command prompt in windows as well where we may execute the commands easily. But Windows and Linux have commands with the same name as well.
What files run on Linux?
A RUN file is an executable file typically used to install Linux programs. It contains program data and installation instructions. RUN files are often used to distribute device drivers and software among Linux users. You can execute RUN files in the Ubuntu terminal.
How to run .bat(Batch) Files on Linux (Ubuntu)
45 related questions found
Why is permission denied Linux?
While using Linux, you may encounter the error, “permission denied”. This error occurs when the user does not have the privileges to make edits to a file. . Other users, however, may not be allowed to make such edits. Remember that only root or users with Sudo privileges can change permissions for files and folders.
Can you run EXE files on Linux?
1 Answer. This is totally normal. .exe files are Windows executables, and are not meant to be executed natively by any Linux system. However, there's a program called Wine which allows you to run .exe files by translating Windows API calls to calls your Linux kernel can understand.
Is Windows a Linux terminal?
Windows Terminal is a modern terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and Windows Subsystem for Linux (WSL).
Is Windows Terminal like Linux?
The Windows Terminal is a modern, fast, efficient, powerful and productive terminal application. It combines many command-line tools and shells such as Command Prompt, PowerShell and WSL (Windows Subsystem for Linux).
Is CMD a terminal?
So, cmd.exe is not a terminal emulator because it is a Windows application running on a Windows machine. There is no need to emulate anything. It is a shell, depending on your definition of what a shell is.
What are .sh files in Linux?
An SH file is a script programmed for bash, a type of Unix shell (Bourne-Again SHell). It contains instructions written in the Bash language and can be executed by typing text commands within the shell's command-line interface.
What is the Linux equivalent of a batch file?
Batch file equivalent in linux is shell script (. sh). You can use gedit, vim or any other text editor available to create one.
How do I run a .sh file in Linux?
- Select the file using mouse.
- Right-click on the file.
- Choose Properties:
- Click Permissions tab.
- Select Allow executing file as a program:
- Now click the file name and you will be prompted. Select “Run in the terminal” and it will get executed in the terminal.
Can I run Windows .bat files in Ubuntu?
I want to run a .bat file in ubuntu, but it just opens the text editor. Here's the code of the .bat file(you can play it):
@echo off set /a guessnum=0 set /a answer=%RANDOM% echo Welcome to the Guessing Game! echo. echo Try and Guess my Number! echo. echo. goto guess :guess set /p guess= set /a guessnum=%guessnum% +1 if %guess% GTR %answer% ECHO Lower! if %guess% LSS %answer% ECHO Higher! if %guess% EQU %answer% GOTO EQUAL goto goto guess :equal echo Congratulations, You guessed right. echo. echo It took you %guessnum% guesses. echo. pause
The file is seen as being text; hence opening in the text editor. Files are marked as executable via chmod (or GUI tools) which you didn't do, but the file must have an interpreter installed that knows how to execute it (usually the type of file can be determined, but the shebang on first line is always a safety item to ensure it's interpreted correctly - your file has none). You'll need to add software that knows how to interpret it, as it's not BASH script, not perl, not python, not CSH etc.
This code is erroneous, so there is no output from this batch file. The statement goto top can't be executed because there is no label named :top in this batch file. Debugging batch files is off topic at Ask Ubuntu. Try asking for help at a Windows site or Stack Overflow.
2 Answers 2
By the looks of it, most of it (the parts using the “echo” command) should work, but not the batch-specific parts (e.g. “goto”). But you should be able to convert it to a shell script and then it might work, or you may be able to emulate it within Ubuntu.
Edit: I've converted it, it appears to be incomplete. It appears to have converted the "if" parts, but not anything else. Let me know if it works (I highly doubt it), I'll also try it personally. I hope it helps. (Moderators, please update this answer with a fully converted script if possible.)
export -a guessnum=0 export -a answer=$ echo Welcome to the Guessing Game! echo "" echo Try and Guess my Number! echo "" echo "" export -p guess= export -a guessnum=$ +1 if $ echo Lower! if $ echo Higher! if $ echo EQUAL goto top :equal echo Congratulations, You guessed right. echo "" echo It took you $ guesses. echo "" pause
How do I create a batch file and run it? [duplicate]
Your question is more likely to receive useful answers if it contains some specifics. Such as what type of data is to be processed, including realistic examples of input and output.
@SergiyKolodyazhnyy The duplicate nominee is closed as too broad. As such the close vote on this one should be "too broad" as well. That said it seems like a reasonable question to me as I was once in the dark myself 🙂
@WinEunuuchs2Unix It is closed but does have an accepted answer, which will give OP what they want, or at least a starting point.
@EliahKagan If a mod agrees perhaps he can reopen that one and then merge the answers from here to there?
@WinEunuuchs2Unix That question, which this received close votes to be duped to, was actually reopened a few hours ago, then closed again as duplicate of that highly voted question. Both of them are listed as "originals" in the duplicate banner here (i.e., this question is duped to both of them). So if answers are to be merged, they'd probably be put there. Do you think that would be useful?
3 Answers 3
To create one use the .sh extension but it doesn't really matter but it helps future users to quickly determine which file type it is. The bat name is mostly used on Windows but in Linux file name extensions do not really matter. Meaning I can call my file say run.de and it would still run in bash file but I believe it's a good practice to name them with the .sh file extension.
For the editor, part uses any that is best for you between nano vim gedit emacs , but I believe gedit would be nice to start with.