Execute commands from an input file
I know this is probably a very simple task but I'm new to this and have been trying to understand how to accomplish the following. I have a list of commands that are stored in a file. Lets call that input1. I want to take that file (input1) and execute every one of those commands from a script. The output will all go to a single file. What I have tried is the following:
#!/bin/bash cat /root/scripts/binary_list.txt | while read i do $i >> /tmp/ASYS/RO33730/patchlvlout.out 2>&1 echo $i -- This is just to see what is comming thru the file. done Every time i run this I receive an error stating that command cannot be found. If I string all the commands in a script without pulling them thru a file or putting in a loop the commands work ok. The proiblem seems to be when using the file as input I must be missing something. Any help would be appreciated. Thanks. |
@ Reply
Hi mfarch99,
Welcome to LQ!!! As you said that the commands work when you put them in a file and then run that file as a script. However, it does not work when you use this file as an input. If that is the case then the following script should do: Code:
#!/bin/bash |
Executing commands and redirecting to output file
I have tried your script; it works fine.
It is possible that the directory you have the script file in is not in your path. My script is stored in 'exlist' (no quotes). To execute it, I navigate to the directory where exlist is stored and type './exlist' (again, no quotes). Hope this helps... Dave |
Thank you for the responses. The input file was bad. I re-created the file and the script worked fine. Again, Thank you for the responses..
|
Here is another question on this. IS there a way to print the command that is executing the file into the output file? In other words, every time the command is executed I want to see the command and the output from that command in one output file.
|
@ Reply
Just use echo $i and then $i as follows (copied your script as an example):
Code:
cat /root/scripts/binary_list.txt | while read i |
Greetingz!
Try this, instead; Code:
if [ -r ./commands.txt ]; then |
More linux commands
Here is a list of the most used linux commands that will help you to write shell programs
|
All times are GMT -5. The time now is 02:13 AM. |