Solved

pre-buffer YES for script commands

Posted on 2007-03-27
13
400 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Openwrt vnstat 9 153
How to clone solaris 10 machine 33 112
unix example issues 18 73
mobaxterm not able to change directory 28 103
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

911 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

27 Experts available now in Live!

Get 1:1 Help Now