- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- in .profile, how to write "waiting 10 sec" and "us...
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
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
04-04-2008 12:54 PM
04-04-2008 12:54 PM
Hi
I have been modifying the ".profile" file.
...
echo "A B : \c"
read REPLY
if [ "$REPLY" = "A" -o "$REPLY" = "a" ]
then
do actionA
fi
...
if [ "$REPLY" = "B" -o "$REPLY" = "b" ]
then
do actionB
fi
...
How to do/write when $REPLY = enter (user doesn't input A or B, just click "enter") or waiting 10 sec then system auto choose A, in other words: if [ "$REPLY" = " (enter)???" -o waiting = 10sec] then do actionA fi. How to write waiting 10 sec and input "enter"
Any answers will be very appreciate.
-G
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2008 01:37 PM
04-04-2008 01:37 PM
Solutionsleep trap
found (among other things) my answer in:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1119616
Even if it offers nothing else, my example
uses a ten-second delay, so it should need a
bit less editing than it might otherwise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2008 01:40 PM
04-04-2008 01:40 PM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
Thank you very much for your fast reply.
I will check the hyperlink that your posted.
Have a good day.
-G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2008 03:33 PM
04-04-2008 03:33 PM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
If you are doing lots of ifs, you may want to switch to a case:
case in "$REPLY"
A|a) actionA ;;
B|b) actionB ;;
*) # not one of the above
;;
esac
If you just have one letter replies and/or where you don't care about upper vs lower case you can have it upshifted or downshifted:
typeset -u REPLY
typeset -l REPLY
You can also use select to give a menu of selections.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2008 08:26 AM
04-05-2008 08:26 AM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
echo "A B: \c"
REPLY=$(line -t 10)
case "$REPLY" in
a|A ) doActionA
;;
b|B ) doActionB2
doActionB2
;;
"" ) doEnterOnly
;;
* ) doNeitherAorB
;;
esac
Now if you require "A" or "B" and must exit if no answer (just "enter") or no answer in 10 seconds, change to an endless loop until an acceptable answer is given:
while :
do
echo "A B: \c"
REPLY=$(line -t 10)
case "$REPLY" in
a|A|b|B ) break ;;
"" ) echo "No answer, exiting"
exit
;;
* ) echo "wrong answer, try again"
;;
esac
done
The $REPLY variable will have the answer given. The case statement allows for partial answers using regular expressions as in a*|A*|b*|B* ) to match anything starting with a,b,A,B and so on.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 07:13 AM
04-07-2008 07:13 AM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
Thank you very much for your good suggestions and details above.
Have a good day.
-Gary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 07:31 AM
04-07-2008 07:31 AM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
One more question for you:
Actually, my goal is that: When oracle user login, System will gives him two or more options: A and B (C,D...) for enter different databasesA, B ... If oralce user doesn't choose any one, just wait 10 sec, system will auto execute actionA goes to the databaseA eq. the user choose A. In other words, in file /home/oracle/.profile, I wanna set actionA, databaseA is the default if user doesn't choose anything.
Does it could be achieved in HP-UX script?
Thanks
-G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 08:13 AM
04-07-2008 08:13 AM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
> In other words, in file /home/oracle/.profile, I wanna set actionA, databaseA is the default if user doesn't choose anything.
Bill has already shown you how to do this. An empty response, denoted by "" will signify either the absence of any user input in the alloted 10-seconds or that the user simply pressed the return/enter key.
A bit more of the script that Bill offered you looks like the following. Like Dennis, I like to use the 'typeset' to unconditionally translate all input to lowercase thereby making subsequent conditional testing easier:
# cat .somepiece
#!/usr/bin/sh
typeset -l REPLY
function doActionA
{
echo "doing A"
}
function doActionB2
{
echo "doing B"
}
function doNeitherAorB
{
echo "doing neither A nor B"
}
echo "A B: \c"
REPLY=$(line -t 10)
case "$REPLY" in
a ) doActionA
;;
b ) doActionB2
doActionB2
;;
"" ) echo "Default action taken!"
doActionA
;;
* ) doNeitherAorB
;;
esac
...If this is the sole objective of the user's profile, I would consider having the login profile 'exec' a complete, external script where the script can be maintained unto itself. Shell functions in login profiles can also have annoying side effects. Be aware, too, that adding user input logic to a login profile means that unless you test for "interactivity" with a terminal, the profile becomes difficult to source (read) for other purposes. These are whole discussions aside.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 08:57 AM
04-07-2008 08:57 AM
Re: in .profile, how to write "waiting 10 sec" and "user reply = enter"
Thanks for your reply.
I will check it later as a urgent meeting.
-G