- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- yes or no
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 03:24 AM
11-20-2006 03:24 AM
I just need a simple piece of code. Here is what I am trying to do
I just want to prompt a user with "This will erase demo with no backup" Continue y or n.
y - results in a rm command
n - prompts
"Please have a backup run" and kicks them to a prompt
Any help would be great, sorry for the rookie question
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 03:31 AM
11-20-2006 03:31 AM
Re: yes or no
echo "This will erase demo with no backup. Continue? (y/[n]): \c"
read ANSWER
case ${ANSWER} in
y|Y) rm whatever
;;
*) echo "Please have a backup run"
;;
esac
This assumes a "no" response for anything other than y or Y.
Jeff Traigle
- Tags:
- case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 03:34 AM
11-20-2006 03:34 AM
Re: yes or no
I use something like the following:
echo "This will erase demo with no backup. Continue y or n"
read ans
if [ $ans == yes ]; then
rm command
else
prompts
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 03:37 AM
11-20-2006 03:37 AM
Re: yes or no
You can adapt this to your needs:
#!/usr/bin/sh
typeset -l CHOICE
while true
do
clear
echo "\nThis will erase demo with no backup\n"
echo "\n >>> Enter < y > to remove"
echo "\n >>> Enter < n > to specify"
echo "\n*---> \c"
#
read CHOICE
case ${CHOICE} in
y ) echo "\nNow removing..."
echo "press ENTER to resume"
read REPLY
continue
;;
n ) exit
;;
"") continue
;;
esac
done
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 04:00 AM
11-20-2006 04:00 AM
Re: yes or no
It is not wrapping my text (I changed it a little. I am getting this
and:
How can I get it to split to the next line?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 04:02 AM
11-20-2006 04:02 AM
Re: yes or no
cp /fpc/oracle/8.0.6/network/admin/listener.ora /drp/demofiles
cp /fpc/oracle/8.0.6/network/admin/tnsnames.ora /drp/demofiles
echo "This will erase prod 32 demo with no backup. It will also bring down test5
4 and prod40. Continue? (y/[n]:\c"
read ANSWER
case ${ANSWER} in
y|Y ps -ef | grep oracle | grep -v grep | awk '{print $2}' | xargs kill -9
cd /fpc
rm -rf *
;;
*) echo "Please have a backup run"
;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 04:26 AM
11-20-2006 04:26 AM
Re: yes or no
PS3='This will erase demo with no backup (Pick 1-3)? '
select i in "y" "n" "*"
do
case $i in
"y"|"Y") echo Will run the rm command
break
;;
"n"|"N") echo Please have a backup run!!!
exit
;;
"*") echo "Bye Bye..."
sleep 2
exit
;;
esac
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 04:26 AM
11-20-2006 04:26 AM
Re: yes or no
Something like the following:
WAS:
echo "This will erase prod 32 demo with no backup. It will also bring down test5
4 and prod40. Continue? (y/[n]:\c"
TRY:
echo "This will erase prod 32 demo with no backup. It will also bring "
echo "down test54 and prod40. Continue? (y/[n]:\c"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 04:28 AM
11-20-2006 04:28 AM
Re: yes or no
ie.
echo "abc\ndef"
will produce
abc
def
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 11:30 PM
11-21-2006 11:30 PM
Re: yes or no
So this is what I have so far
cp /fpc/oracle/8.0.6/network/admin/listener.ora /drp/demofiles
cp /fpc/oracle/8.0.6/network/admin/tnsnames.ora /drp/demofiles
echo "This will erase prod 32 demo with no backup. It will also bring down\n tes
t54 and prod40. Continue? (y/[n]): \c"
read ANSWER
if [$ANSWER ==y ]; then
ps -ef | grep oracle | grep -v grep | awk '{print $2}' | xargs kill -9
cd /fpc
rm -rf *
else
echo "Please have a backup run"
fi
And this is what it is doing
# ./s1.sh
This will erase prod 32 demo with no backup. It will also bring down
test54 and prod40. Continue? (y/[n]): y
./s1.sh[5]: [y: not found.
Please have a backup run
[root:demoglo:/drp]
#
Any tips would be great... Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 11:44 PM
11-21-2006 11:44 PM
SolutionYou need whitespace around the brackets:
# if [ $ANSWER = "y" ]; then
You also need to use "=" since this is the shell's test for string equality.
*ALSO* do yourself a favor: NEVER use 'rm -rf' uness you are dead sure that you are removing what you think you are! In this script, at least, do:
# cd /fpc && rm -rf *
...in this way, *only* if the directory '/fpc' exists and you successfully change into it will the 'rm' be executed. The way you coded you script would mean a missing '/fpc' directory would leave your PATH wherever it was when you ran the script. If you were at the root directory as root, well, you just gave yourself a chance to practice a full server rebuild!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 11:52 PM
11-21-2006 11:52 PM
Re: yes or no
instead of:
if [$ANSWER ==y ]; then
try:
if [ $ANSWER = "Y" -o $ANSWER = "y" ] ; then
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 11:56 PM
11-21-2006 11:56 PM
Re: yes or no
as mentioned by JRF above, pay attention to the whitespaces.
you may wish to copy it from my last post and paste it in your script.
CAUTION!
========
above all, when testing your script, disable the actual command inside the scripts! only use echo commands
good luck
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 11:58 PM
11-21-2006 11:58 PM
Re: yes or no
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 11:59 PM
11-21-2006 11:59 PM
Re: yes or no
Instead of testing for lowercase and uppercase letters, add 'typeset -l' declaration thusyly:
# typeset -l ANSWER
...
# read ANSWER
...
This automatically converts all uppercase letters to lowercase ones when the assignment is made. Hence you can respond in uppercase and test only lowercase letters.
Regards!
...JRF....
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2006 04:44 AM
11-22-2006 04:44 AM
Re: yes or no
One other comment: using a kill -9 to shutdown a database is almost guaranteed to corrupt your database somewhere down the line.
If you read the man page on kill(1), you will see that the -9 switch means unconditional, cannot-be-ignored kill. This means that the process has not time to close files and clean up after itself.
Why not use the init.d script to shut down the DB in an orderly manner?
Just my 2cts,
Mark