Passing a paramter to a list of command in another file
Hello all
I am attempting to write my first ever script from scratch and making some progress. My first shell script file executes a list of commands contained in a second file. I need to pass a parameter to this command file how do I do this??? Hope this makes sense... t. |
Quote:
|
Sorry...okay
Im am trying to pass a variable 'x' lets say to /etc/bacula/bconsole -c bin/bconsole.conf </bin/baculacommands.sh. The first part before the < is the bacula console program and after the < is a file which contains a list of commands that needs to be executed by the console program. I need to pass a variable to this command list file as well how do I do this and how do i ref the variable in the second file... Hope this is much more clearer... Thanks. |
Quote:
I think the problem is you are asking for the impossible so it's hard to understand but easy for you to conceptualise. If you want to write a script that will pass a combination of fixed commands and variable data to an external program that will take its input from stdin (as bconsole does) then it is better to use a "here document" or a "here string" rather than a file because you can easily change the variable data and your script will be briefer and easier to understand. The alternative is to write the input file on-the-fly but it's more obscure and complex. Here's a "here string" example which also captures output from bconsole in case the script is not being run interactively (you could log it instead of echoing it) Code:
buf="$( $bconsole <<< "@output /dev/null |
HI Catkin thanks for your response but I am so confused! :)
Here is an example of my files:- so my bacula.sh file #! /bin/bash Vol=$(echo "st storage=DEV6-Changer" | bconsole | grep Volume: | cut -d':' -f2) echo $Vol /etc/bacula/bconsole -c bin/bconsole.conf </bin/baculacommands.sh exit 0 For my baculacommands.sh file i have something like:- mount purge 3 8 I just want to add the $Vol name that I have found from my first file to the bottom of my second file - but am clueless as to how to pass the variable to this file... Hope this is clearer... |
Based on your script but using a here string instead of the file and omitting capturing the bconsole output
Code:
#! /bin/bash Code:
#! /bin/bash |
Hi Catkin
And thanks for ALL your help :) Much appreciated! I did resolve the problem in the end. Probably not as simple or clean as your code but it works. I simply added lines to clear the content of the baculacommands file each time and then add the commands that I want to execute to that file along with the volume name as a string! Works a charm! Thanks again! :) |
Quote:
Glad you found a solution that works for you. The Thread Tools menu can be used to mark the thread SOLVED. |
All times are GMT -5. The time now is 06:26 AM. |