Solved

pre-buffer YES for script commands

Posted on 2007-03-27
13
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

726 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