- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: How to by pass a prompt in a script.
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
Discussions
Discussions
Forums
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
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
тАО03-26-2007 09:59 AM
тАО03-26-2007 09:59 AM
echo "Enter an environment TST,DEV,PRD,DMO, or PERF:"
read ENV
#
case $ENV in
TST|1)
echo "You entered (TST) :\n";
export MYBAN=TEST
export PSADM=/u04/psoft/CRM89TST/pt845/crm89/appserv
export PS_HOME=/u04/psoft/CRM89TST/pt845/crm89
. /u04/psoft/CRM89TST/pt845/crm89/psconfig.sh
;;
DEV|2)
echo "You entered (DEV) :\n";
export MYBAN=DEVELOP
export PSADM=/u04/psoft/CRM89DEV/pt845/crm89/appserv
export PS_HOME=/u04/psoft/CRM89DEV/pt845/crm89
. /u04/psoft/CRM89DEV/pt845/crm89/psconfig.sh
;;
Since we want to shutdown PeopleSoft using a cron job, we do not want it to be prompted and continue with the shutdown as normal. Since we have 5 or 6 different environment the user needs to put what environment will be working with and it gets re-directed to his choice. If you could help on what do I need to put in order to by pass the prompt, I would really appreciated.
Thank you so much!
** removed email address to comply with forum guidelines **
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 10:11 AM
тАО03-26-2007 10:11 AM
SolutionEssentially we set ENV = "" and then assign it to ${1}. If the length of ${ENV} is zero then you need to prompt the user otherwise enter the case statement.
Something like this:
#!/usr/bin/sh
typeset ENV=""
if [[ ${#} -gt 0 ]]
then
ENV=${1}
shift
fi
if [[ -z "${ENV}" ]]
then
echo "Enter an environment TST,DEV,PRD,DMO, or PERF: \c"
read ENV
fi
case ${ENV} in
.... the rest is the same as your existing script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 05:35 PM
тАО03-26-2007 05:35 PM
Re: How to by pass a prompt in a script.
if tty -s
then
# we have a TTY and can ask things
echo "Enter an environment:"
read ENV
#...
else
# we do not have a TTY.
# Don't ask anything, because the prompt
# might break things like rcp/scp/rdist/
# rsync or cron jobs.
# Set the environment variables to some
# sensible default values.
fi
- Tags:
- tty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 05:41 PM - edited тАО10-09-2011 08:57 PM
тАО03-26-2007 05:41 PM - edited тАО10-09-2011 08:57 PM
Re: How to bypass a prompt in a script.
You can also use the following to check to see if you are an interactive shell:
if [ "${-%%*i*}" != "$-" ]; then
But perhaps Matti's solution would be better in scripts, where mine better for .profile.
Also, you should NOT be using ENV for a variable because ENV has a special meaning for a real shell!
- Tags:
- env
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2007 08:08 PM
тАО03-27-2007 08:08 PM
Re: How to by pass a prompt in a script.
just another possbile test:
if [[ $(tty) != "not a tty" ]]; then
# BEGIN interactive section
# END intercative sectin
put here all yoy command which requires
terminal (i.e.: terminal setup) or
interaction with user
else
# BEGIN batch section
# END batch sectin
fi
HTH,
Art