LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-14-2006, 06:24 AM   #1
neil
Member
 
Registered: Jul 2001
Location: Kent, UK
Distribution: AIX/Gentoo/Fedora/Solaris 8/9/10
Posts: 100

Rep: Reputation: 15
Bash tricks


Hi,

I am trying to get a script to run during boot up. I need this script to run an executable that does a lights out firmware upgrade on a DL360. In itself this isnt a problem. I have built a boot disk and I can get it to run scripts. However my Bash scripting isnt too hot.

The problem is, when the binary runs it prompts me for a yes or no. I need the script that execs the binary to give it a 'y'

something like ?
./firmware.bin < echo 'y'

Please help. Ive spent ages getting this far, and now its getting silly.

Cheers,
Neil.
 
Old 11-14-2006, 06:30 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Take a look at the yes command.

Something like yes | ./firmware.bin should work.

Hope this helps.
 
Old 11-14-2006, 11:48 AM   #3
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
Although we talk about a here document, it is supposed to be a construct within the same script. This is an example that installs a package automatically, eventhough you should normally confirm:

#!/bin/bash

# This script installs packages automatically, using yum.

if [ $# -lt 1 ]; then
echo "Usage: $0 package."
exit 1
fi

yum install $1 << CONFIRM
y
CONFIRM

And this is how the script runs. When prompted with the "Is this ok [y/N]" string, the script answers "y" automatically
 
Old 11-15-2006, 02:32 AM   #4
neil
Member
 
Registered: Jul 2001
Location: Kent, UK
Distribution: AIX/Gentoo/Fedora/Solaris 8/9/10
Posts: 100

Original Poster
Rep: Reputation: 15
Thankyou very much for the answers, Unfortunatly I have other problems as I had to reduse the size of Libraries and the script wont run at all at the moment. I get an error saying the ash shell cant find the executable, which isnt true. The shell cant find something that the executable is calling. Oh well.

I will try the answers when I get around this one.

This is not using yum to install a rpm, but rather a binary executable that appears to update the (iLo) lights out firmware on a DL360 and configures the iLo based on a XML configuration file.

So I can kick it off with ./ or the full path name. I placed it in /bin.

echo "Ugrading the firmware to version 1.88"
/bin/CP006953.scexe

This definately works fromn the command line but Im there to answer 'y' to the prompt.

Thank you very much for the replies. Any other suggestions I can try would be appreciated.

I will come back to let everyone know how I get on.

Cheers.
 
Old 11-15-2006, 09:19 AM   #5
doublejoon
Member
 
Registered: Oct 2003
Location: King George, VA
Distribution: RHEL/CentOS/Scientific/Fedora, LinuxMint
Posts: 366

Rep: Reputation: 44
Quote:
Originally Posted by ygloo
Although we talk about a here document, it is supposed to be a construct within the same script. This is an example that installs a package automatically, eventhough you should normally confirm:

#!/bin/bash

# This script installs packages automatically, using yum.

if [ $# -lt 1 ]; then
echo "Usage: $0 package."
exit 1
fi

yum install $1 << CONFIRM
y
CONFIRM

And this is how the script runs. When prompted with the "Is this ok [y/N]" string, the script answers "y" automatically

never head of CONFIRM.....good stuff.... I will use it
 
Old 11-15-2006, 12:15 PM   #6
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
"<< CONFIRM
y
CONFIRM"

can use any word in place of "CONFIRM"

Last edited by ygloo; 11-15-2006 at 12:17 PM.
 
Old 11-15-2006, 12:39 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,693
Blog Entries: 54

Rep: Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961
can use any word in place of "CONFIRM"
In shell terms this is called a "here document". It's just redirection.
 
Old 11-15-2006, 12:39 PM   #8
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
Quote:
Originally Posted by doublejoon
never head of CONFIRM.....good stuff.... I will use it
As ygloo stated, but didn't really elaborate on, any string can be used instead of CONFIRM. I usually use EOF myself, or something a bit more descriptive if I am using multiple here documents in the same script.

Basically what a here document is, is a set of commands or responses that get passed to a command. For example, you can ...

Code:
$ vi some_file <<EOF
:%s/something/something else/g
:wq
EOF
Which would do a global search and replace in the some_file using vi.

NOTE that if you were to use '<< EOF', then you must have a space in front of the terminating EOF as well. It has tripped me up a few times.

If you want to know more, check out here documents in the Advanced Bash Scripting Guide. Specifically here.

Last edited by Hobbletoe; 11-15-2006 at 12:40 PM.
 
Old 11-16-2006, 04:49 AM   #9
neil
Member
 
Registered: Jul 2001
Location: Kent, UK
Distribution: AIX/Gentoo/Fedora/Solaris 8/9/10
Posts: 100

Original Poster
Rep: Reputation: 15
Hi All,

./firmware.bin < echo 'y'
didnt work Im afraid,

However
echo 'y' | ../bin/binaryfile
did

I guess you would use the "CONFIRM" script above like a response file in Solaris Jumpstart installation.

Thanks for all teh responses. My problem is solved and the first answer got me there.
Cheers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Tricks and hints neo77777 Linux - General 145 08-24-2009 03:38 AM
Shell tricks? GaijinPunch Linux - General 2 12-17-2003 11:45 PM
m$'s tricks yenonn General 4 10-09-2003 11:53 PM
Does ebay really have tricks ? phreakazoid General 2 07-23-2003 09:53 AM
Tips and Tricks Westdog976 LQ Suggestions & Feedback 8 07-14-2003 01:24 PM


All times are GMT -5. The time now is 11:27 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration