• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

pre-buffer YES for script commands

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
huffmana
Asked:
huffmana
  • 5
  • 4
  • 4
2 Solutions
 
TintinCommented:
echo  y | somecommand

or for multiple responses

echo  "y\ny\ny" | somecommand
0
 
yuzhCommented:
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
 
yuzhCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
huffmanaAuthor Commented:
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
 
yuzhCommented:
make it looks like:
(ufsdump 0f - /dev/rdsk/c1t0d0s0 | ufsrestore xf - )<EOF
y
y
EOF


0
 
huffmanaAuthor Commented:
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
 
huffmanaAuthor Commented:
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
 
TintinCommented:
Some commands read directly from the tty.  For that, you'll need to write an expect script.
0
 
huffmanaAuthor Commented:
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
 
TintinCommented:
Do they let you install Perl modules?  You can write Perl/Expect scripts without having to install expect.
0
 
huffmanaAuthor Commented:
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
 
yuzhCommented:
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
 
TintinCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 5
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now