- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting question
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
тАО11-11-2004 07:20 AM
тАО11-11-2004 07:20 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 07:32 AM
тАО11-11-2004 07:32 AM
Re: scripting question
I assume you are using case statement. I would do like this
case $something in
"opt1")
some_commands
;;
"opt2")
echo "Enter the password for user"
su - user1 -c "
command1
command2
command3"
;;
*) echo "invalid choice"
;;
esac
If the option is "opt2", then it will switch user to user1 and then execute the commands enclosed in "". SU itself will ask for the password so you don't have write steps for it.
-Sri
- Tags:
- case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 07:35 AM
тАО11-11-2004 07:35 AM
Re: scripting question
VALID=0
while [ $VALID -ne 1 ]; do
echo "Enter user name to become:\c"
read USERNAME
VALID=`grep -c "^$USERNAME" /etc/passwd`
done
su - $USERNAME
which will switch to the user requested, prompting for the user's password--unless being performed as root or that user.
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 07:42 AM
тАО11-11-2004 07:42 AM
Re: scripting question
an example of a menu where you have to supply the oracle user's pw for option no. 2, unless you are root:
PS3="Enter item: "
select choice in ls date quit
do
case $REPLY
in
1) ls;;
2) su oracle -c date;;
3|O|q) exit ;;
*) echo "Invalid choice" ;;
esac
done
regards,
John K.
- Tags:
- select
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 07:46 AM
тАО11-11-2004 07:46 AM
Re: scripting question
print "Catalyst Script MENU"
PS3="Test Menu, enter choice:"
select clean_menu in "Verify Catalyst Packages" "Set Maintenance Flag on Catalys
t" "Clearing Maintenance Flag on Catalyst" "Reset RF for Deal Instance on Cataly
st" "Reset RF for Main Instance in Catalyst" "Exit"
do
case $clean_menu in
"Verify Catalyst Packages")
/usr/sbin/cmviewcl;;
"Set Maintenance Flag on Catalyst")
/apps/bin/set_cat_maint_mode;;
"Clearing Maintenance Flag on Catalyst")
/apps/bin/clr_cat_maint_mode;;
"Reset RF for Deal Instance on Catalsyst")
echo "Enter the password for user"
su - root;;
an example of the script i'm using and when i choose option 4 it doesn't do anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 09:03 AM
тАО11-11-2004 09:03 AM
Re: scripting question
Couple of problems in your script.
1. Correct the string "catalsyst" in option4.
2. Add option5 and option 6 also like
"Reset RF for Deal Instance on Catalyst")
echo "Enter the password for user"
su - root;;
"Reset RF for Main Instance in Catalyst"
some_function;;
"Exit")
exit;;
esac
done
The text has to match exactly... otherwise it won't work.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 09:24 AM
тАО11-11-2004 09:24 AM
Re: scripting question
Thanks for heads up on the typo; however now I'm getting a syntax error on my Exit line. Its saying `) is unexpected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 09:28 AM
тАО11-11-2004 09:28 AM
Re: scripting question
"Reset RF for Deal Instance on Catalyst")
echo "Enter the password for user"
su - root;;
"Reset RF for Main Instance in Catalyst")
some_function;;
"Exit")
exit;;
*)
echo "invalid option";;
esac
done
You will need to fill in "some_function".
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 09:49 AM
тАО11-11-2004 09:49 AM
Re: scripting question
Thanks for the help thus far, really appreciate it; however, one more question, on option five I need to su to another user id and when I plugged that option in, I'm receiving invalid option.
"Reset RF for Deal Instance on Catalyst")
echo "Enter the password for Deal"
su - deal;;
"Reset RF for Main Instance on Catalyst")
echo "Enter the password for Main"
su - main;;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2004 10:22 AM
тАО11-11-2004 10:22 AM
Re: scripting question
-Sri