Register
It is currently Sun Nov 23, 2014 7:13 pm

BASH-script for run outside program, that ask prompt (y/n)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue Mar 23, 2010 3:42 am   

Joined: Tue Mar 23, 2010 3:11 am
Posts: 2
Hello all
I don't have experience with BASH.
But I need make BASH-script for run automatically outside program, that ask prompt (y/n)... and script must response for it

For example, how can I create script, for automatically copy file t1 to file t2 using command "cp" with option "-i",
and if file "t2" exist (command cp will ask: cp: overwrite `t2'? , script should response "y" for rewrite file?

Code:
#!/bin/sh
# dialog.sh

echo "Start!"
cp -i t1 t2


Thank you for any answers!


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 6:14 am   

Joined: Tue Mar 02, 2010 9:55 pm
Posts: 24
Location: Canada
If your going to overwrite the file always, why are you prompting yes or no...just overwrite the file.


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 6:22 am   

Joined: Tue Mar 23, 2010 3:15 am
Posts: 2
Something like this perhaps:

Code:
if [ -f t2 ]
then
echo t2 exists!
else
echo t2 does not exist
cp -i t1 t2
fi


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 7:22 am   

Joined: Tue Mar 23, 2010 3:11 am
Posts: 2
Thank you for the answers! But I don't need program to copy file. I put it for example...

I have some program "upgrade_export" to export checkpoint firewall configuration. When it works, it ask prompt (y/n) for continue...
I don't know how create BASH-script, which will answer "y" instead of me...

Code:
#!/bin/sh
# export-config.sh

echo "Starting Upgrade Export Configuration !"
$FWDIR/bin/upgrade_tools/upgrade_export backup-config.tgz
...


Please, help me!


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 8:39 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
I think I remember seeing some code that automated a Java installation, which requires a yes/no agreement. They used yes.

From the man page: "yes - output a string repeatedly until killed." By default, it puts out a 'y', but you can specify the string.

Just pipe yes into the program:
Code:
yes | upgrade_export


- thobbs


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP