Is it possible to send commands to a running script with a bash script in linux?
for example say that I have a python script with a couple of inputs, can I somehow use a bash script to handle these inputs?
Related
I am trying to make a .sh file that when clicked it runs the script inside. I am trying to recursively find a certain string value inside the contents of the files from a given folder, using $ grep -r "word" /home/folder_name but I don't know how to do so without running the script in terminal.
Any ideas for this?
Linux shell scripts can be written very basically.To make a shell script, start the script with #!/bin/sh and add normal linux commands. That is a simple explanation, but it is sufficient for most simple scenarios.
Example:
#!/bin/sh
echo "Hello, World!`
I have a batch file that bashes into the linux subsystem I have on Windows 10 that tries to execute commands via the linux system. However, it doesn't execute any commands after the bash command. Here is an example:
bash
cd Documents/CS/DS
This just bashes into whatever directory the file is run from instead of CS/DS consistently. Is there anyway to have the batch file execute the rest of the commands?
When you run bash like that, you are sending execution into that executable. Launch bash as a separate process:
`start "bash" bash.exe`
Bash won't execute the rest of your cmd script. Cmd.exe processes cmd/bat files, bash only executes bash commands and scripts.
I was hoping for some advice on using the subprocess module.
I'm trying to run a bash job within a python script so my bash command (in the right directory) is: ./program myjob.inp
This is just running the executable "program" with myjob.inp being the input file (and my python script constantly updates myjob.inp).
I know that if I just wanted to run "program", I could do something like:
with open("tmp.dat","w") as fstore_tmp:
subprocess.call(["./program"], stdout = fstore_tmp)
However, I can't figure out how to run the job taking in the input file myjob.inp such that it's doing the equivalent of ./program myjob.inp. I tried:
with open("tmp.dat","w") as fstore_tmp:
subprocess.call(["./program", "myjob.inp"], stdout = fstore_tmp)
However, that doesn't seem to be working. Does anyone have any suggestions? Thanks!
I have one script which runs in Bash and and other which runs in tcsh.
I need to run them both from the same script. How can I create a script that
can run both bash and tcsh commands?
Most shells have an argument which allow you to pass them a string to run as a command, for example, for bash you can run
bash -c "echo this is a bash script; echo lalalala"
to run that string as a script in bash, use this to run the needed shell embedded in the other. This will allow you to make a script in one shell which will invoke the other shell when the other program needs to be run.
If on the other hand they are both properly shebanged begin with #!tcsh or #!bash you can simply run both scripts from the same bash script using:
/path/to/script1 &
/path/to/script2 &
How can i write a shell script that can supervise the input and the output of a running script?
I have another script that will generate results. I want something like trigger to run commands when the other script will generate results.