LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2010, 06:37 AM   #1
tqz
Member
 
Registered: Jan 2008
Posts: 67

Rep: Reputation: 15
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.
 
Old 04-19-2010, 06:42 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Quote:
Originally Posted by tqz View Post
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.
Explain more !!
 
Old 04-19-2010, 06:55 AM   #3
tqz
Member
 
Registered: Jan 2008
Posts: 67

Original Poster
Rep: Reputation: 15
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.
 
Old 04-19-2010, 08:54 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by tqz View Post
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.
Not much clearer!

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
            messages
            @output
            run job="$job_name" level=$job_level yes
            quit" 2>&1
    )"
    echo "DEBUG: buf from run job is '$buf'"

Last edited by catkin; 04-19-2010 at 08:56 AM. Reason: clarity
 
Old 04-19-2010, 10:04 AM   #5
tqz
Member
 
Registered: Jan 2008
Posts: 67

Original Poster
Rep: Reputation: 15
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...
 
Old 04-19-2010, 11:55 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Based on your script but using a here string instead of the file and omitting capturing the bconsole output
Code:
#! /bin/bash

Vol=$(echo "st storage=DEV6-Changer" | bconsole | grep Volume: | cut -d':' -f2)
echo $Vol
/etc/bacula/bconsole -c bin/bconsole.conf  <<< "mount
purge
3
8
$Vol"
If you still want to use a file then
Code:
#! /bin/bash

Vol=$(echo "st storage=DEV6-Changer" | bconsole | grep Volume: | cut -d':' -f2)
echo $Vol
cat /bin/baculacommands.sh > /bin/baculacommands.tmp.sh
echo $Vol >> /bin/baculacommands.tmp.sh
/etc/bacula/bconsole -c bin/bconsole.conf </bin/baculacommands.tmp.sh
exit 0
 
Old 04-20-2010, 04:53 AM   #7
tqz
Member
 
Registered: Jan 2008
Posts: 67

Original Poster
Rep: Reputation: 15
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!
 
Old 04-20-2010, 05:27 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by tqz View Post
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!
Welcome!

Glad you found a solution that works for you.

The Thread Tools menu can be used to mark the thread SOLVED.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing paramter from one script to another script in perl john83reuben Programming 4 02-28-2008 12:42 AM
command want list all in root / by filtering file and directory? hocheetiong Linux - Newbie 2 11-01-2007 02:16 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 08:09 AM
passing a list of arguments to a command hdagelic Linux - General 2 05-09-2005 09:30 AM
can't see root file system with list command fr_baker Linux - General 10 06-07-2004 08:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration