- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script Help
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
02-16-2005 02:08 AM
02-16-2005 02:08 AM
I need it to take users to different instances on an HP-UX server. This is what I have, that's not working though. Maybe someone can help me out here:
#!/bin/ksh
clear
cmd="cd"
echo "What Region ID would you like to login to Today?\n"
echo "\t1) EAST"
echo "\t2) WEST"
echo "\t3) exit"
echo "\nPlease enter choice here ->\c"
read target
echo " --$targ--- "
case $target in
1) target= "cd /east/"
echo " $target "
;;
2) target= "cd /west/"
echo " $target "
;;
3) target= "exit"
echo " $target "
;;
4) echo " Please enter 1,2, or 3 "
exit 0
;;
esac
#clear
echo ">\c"
echo "\nSession Completed, If you would like to exit the system\c"
echo ""
echo "\nType exit, to leave the System\c"
echo "\n\c"
#sleep 2
exit 0
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:17 AM
02-16-2005 02:17 AM
Re: Script Help
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:19 AM
02-16-2005 02:19 AM
Re: Script Help
when you say the script is not working, what is the failure/expected behaviour?
All I should see was that the 1),2) and 3) lines should not have a space between = and "cd..."
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:22 AM
02-16-2005 02:22 AM
Re: Script Help
if you want the script to loop until the user selects 3 to exit, you will need a while statement.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:24 AM
02-16-2005 02:24 AM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:24 AM
02-16-2005 02:24 AM
Re: Script Help
3)
mv $origpfad/* $sichpfad/
;;
4)
mv $sichpfad/* $origpfad/
;;
esac
if I remember correctly, You must either
write
4) mv $sichpfad/* $origpfad/;
;
or
4)
mv $sichpfad/* $origpfad/
;;
(but I'm not really sure.
Best thing would be using
#/bin/ksh -vx
to enable debugging
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:24 AM
02-16-2005 02:24 AM
Re: Script Help
4) choice is incorrect. The case statement is actually a series of regular expression so if 4 is entered, your script would exit. What you probably want is anything not already seen above, so it should be *) not 4).
To avoid problems in the future, always start your script with the correct location for the interpreter: #!/usr/bin/ksh (there is no directory called /bin...the V.4 filesystem layout for user commands is /usr/bin, and /bin is only a symlink that will be removed someday)
To find spelling errors in scripts, start the script with set -u and that would have caught the --$targ-- error.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:26 AM
02-16-2005 02:26 AM
Re: Script Help
You don't say exactly what the problem is.
The first thing I would say is to remove the spaces after the equal signs
i.e.
1) target= "cd /east/"
should be
1) target="cd /east/"
I assume this is just a little test script and that you intended just to echo the commands rather than executing them.
If you want to stop users from "falling off the end" of the script, put the case inside an infinite loop:
while true
do
echo "What Region ID would you like to login to Today?\n"
...
...
case ...
blah
blah
esac
clear
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:27 AM
02-16-2005 02:27 AM
Re: Script Help
You have had some good advice here
Look at
www.shelldorado.com
for more
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:28 AM
02-16-2005 02:28 AM
Re: Script Help
if the user selects 1 you want them to go to a directory /east?
1) target="cd /east"
$target
;;
Please note the lack of space marker between = and " !!!
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:30 AM
02-16-2005 02:30 AM
Re: Script Help
yes, it would be fine, to know where the script is failing.
Which 'echo's' are working?
By the way:
read target
echo " --$targ--- "
I can't imagine that this will work, --$targ--- isn't defined.
HTH
Volkmar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:34 AM
02-16-2005 02:34 AM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:37 AM
02-16-2005 02:37 AM
Re: Script Help
if you want to return to the original point:
orig=`pwd`
$target
.
.
.
cd $orig
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 02:53 AM
02-16-2005 02:53 AM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 03:01 AM
02-16-2005 03:01 AM
Solution. /path/to/script
^
Note space!
Try the following:
#!/bin/ksh
while true
do
clear
cmd="cd"
echo "What Region ID would you like to login to Today?\n"
echo "\t1) EAST"
echo "\t2) WEST"
echo "\t3) exit"
echo "\nPlease enter choice here ->\c"
read target
echo " $target "
case $target in
1) target="cd east/"
echo " $target "
$target
;;
2) target="cd west/"
echo " $target "
$target
;;
3) target="exit"
echo " $target "
break
;;
*) echo " Please enter 1,2, or 3 "
;;
esac
done
pwd
echo ">\c"
echo "\nSession Completed, If you would like to exit the system\c"
echo ""
echo "\nType exit, to leave the System\c"
echo "\n\c"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 04:04 AM
02-16-2005 04:04 AM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 04:06 AM
02-16-2005 04:06 AM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 04:14 AM
02-16-2005 04:14 AM
Re: Script Help
^[[2J^[[HWhat Region ID would you like to login to Today?
1) EAST
2) WEST
3) exit
Please enter choice here -> 2
cd /west/
^[[2J^[[HWhat Region ID would you like to login to Today?
1) EAST
2) WEST
3) exit
Please enter choice here ->2
bfedcat /west/
^[[2J^[[HWhat Region ID would you like to login to Today?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 07:04 AM
02-16-2005 07:04 AM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 09:45 PM
02-16-2005 09:45 PM
Re: Script Help
. ./script.ksh
(dot space dotslashscriptname)
#!/bin/ksh
while true
do
clear
cmd="cd"
echo "What Region ID would you like to login to Today?\n"
echo "\t1) EAST"
echo "\t2) WEST"
echo "\t3) exit"
echo "\nPlease enter choice here ->\c"
read target
echo " $target "
case $target in
1) target="cd /east/"
echo " $target "
$target
break
;;
2) target="cd /west/"
echo " $target "
$target
break
;;
3) target="exit"
echo " $target "
break
;;
*) echo " Please enter 1,2, or 3 "
sleep 2
;;
esac
done
pwd
echo ">\c"
echo "\nSession Completed, If you would like to exit the system\c"
echo ""
echo "\nType exit, to leave the System\c"
echo "\n\c"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2005 11:40 PM
02-16-2005 11:40 PM
Re: Script Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 12:21 AM
02-17-2005 12:21 AM
Re: Script Help
You do this by typing a dot followed by a space BEFORE the name of the script or executable. e.g.
. script
If you don't type a dot and a space before the script name, it will run in a subshell, and that subshell will exit when the script finishes running, taking any changes made in the script with it.
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 04:14 AM
02-17-2005 04:14 AM
Re: Script Help
Thanks again,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 04:15 AM
02-17-2005 04:15 AM