Solved

pre-buffer YES for script commands

Posted on 2007-03-27
13
397 Views
Last Modified: 2013-12-27
I'm trying to write a script that I can run just before repartitioning and setting up metadevices by temporarily booting to a 3rd disk.  But the confirmation prompts are interrupting the script.  Like the "ufsdump 0f - / | ufsrestore xf -" that asks for the following.

set owner/mode for "." ? [yn]

Also newfs has a "Do you want to proceed [y/n]" prompt.

Is there anyway to pre-buffer the YES answer for these commands, like "fsck -y".

Thanks, Allan
0
Comment
Question by:huffmana
  • 5
  • 4
  • 4
13 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 18798495
echo  y | somecommand

or for multiple responses

echo  "y\ny\ny" | somecommand
0
 
LVL 38

Expert Comment

by:yuzh
ID: 18804868
I have use something like the following in script for many years, never have to answer any y/n question!

ufsdump 0f - fs | ( cd /mydir ; ufsrestore rf -)

0
 
LVL 38

Assisted Solution

by:yuzh
yuzh earned 250 total points
ID: 18804893
You can also put all your answers in between EOF,
eg:

command <<EOF
answer1
answer2
...
answerN
EOF

make sure that there is no WITHE space before EOF
0
 

Author Comment

by:huffmana
ID: 18806791
Thanks for your resoonses.  They did not work for the ufs partition copy...  see the following.  

I can perhaps put it in a cron and see if it will abort or run.....

The trouble seems to be have something to do with "newfs /dev/rdsk/c1t0d0s0" that causes the ufrestore to ask:
set owner/mode for "." ? [yn]
Directory already exists, set modes anyway? [yn]

I've looked at the permisions and ownership of "." before and after saying YES but there is no change....  

This seemed to confuse the restore and causes an abort:
cd /tmp/a
ufsdump 0f - /dev/rdsk/c1t0d0s0 | ufsrestore xf - <EOF
y
y
EOF
partial block read: 4 should be 64512
abort? [yn]  
DUMP: Broken  pipe
DUMP: The ENTIRE dump is aborted
abort? [yn]


0
 
LVL 38

Expert Comment

by:yuzh
ID: 18807243
make it looks like:
(ufsdump 0f - /dev/rdsk/c1t0d0s0 | ufsrestore xf - )<EOF
y
y
EOF


0
 

Author Comment

by:huffmana
ID: 18807748
OH :-)

Also, I just thought of something: it works if I do the commands, see after CUT HERE.  So perhaps
I can do this:
# echo "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n" | ./copy_partition.sh

-------------------------CUT HERE--------------------------
# ./copy_partitions.sh
# y
# y
# y
# y
# y
# y
# y
# y
# y
# y


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:huffmana
ID: 18808190
Nop, neither works :-(  Only manually entering the y y y y y y y y y at the command prompt works !
I didn't think that stdin was such a pain in the ....

I still have not tried running from the cron.....
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18812161
Some commands read directly from the tty.  For that, you'll need to write an expect script.
0
 

Author Comment

by:huffmana
ID: 18814194
I've run into this trying to make a ADD-USER script and could only enter the passwd from the keyboard.  The only solution was to add a 3rd party tool.  Unfortunately, I'm not allowed to load EXPECT on the servers here.

But I have learned a lot about stdin in a script thanks to your good advice :-)

Many Thanks, Allan
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18814221
Do they let you install Perl modules?  You can write Perl/Expect scripts without having to install expect.
0
 

Author Comment

by:huffmana
ID: 18814846
Yes I can write perl :-)  Is there a use that needs to be available like "use Net::SNMP;"
This sounds interesting.  I could make the ADD-USER perl script?  Thanks, Allan
0
 
LVL 38

Expert Comment

by:yuzh
ID: 18815093
You can use ksh + expect to write the add-user script, there are examples in EE, just do a search at EE, you should be able to find them.  (I have posted some example at EE before).

Good night to all of you! (my time)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18819768
Strange that they let you install Perl modules but not Expect.  Anyway, I've worked in various "secure" organisations that have all sorts of weird ideas about security.

For Pure Perl Expect, you need Expect.pm and Io::Tty

http://search.cpan.org/~rgiersig/Expect-1.20/Expect.pod
http://search.cpan.org/~rgiersig/IO-Tty-1.07/Tty.pm
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now