Solved

pre-buffer YES for script commands

Posted on 2007-03-27
13
406 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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
 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

839 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