- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Looping a ksh 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
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
06-19-2003 06:42 AM
06-19-2003 06:42 AM
I have created a login termination script. I want to continue looping this script until I type q on the command line. I need to run it manually (policy) and check for login/ids in my script.
How can I create a basic loop to start and return to the beginning after completing each process.
More explaination:
while (I input something)
run my script
go back to top until I input "q".
Thanks in advance,
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 06:48 AM
06-19-2003 06:48 AM
Re: Looping a ksh script
try this:
while true;
do
your commands here;
done;
Use Control+C to stop the loop.
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 06:48 AM
06-19-2003 06:48 AM
Re: Looping a ksh script
while [ 1 ]
do
run script
echo "Quit (q) ? "
read key_stroke
if [ "$key_stroke" = "q" ]
then break
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 06:50 AM
06-19-2003 06:50 AM
Re: Looping a ksh script
Here's one way:
#!/usr/bin/sh
typeset -l REPLY
while [ "${REPLY}" != q ]
do
echo "Choose your poison..."
read REPLY
[ "${REPLY}" = q ] && continue
echo "looping"
done
echo "exiting now"
exit 0
Note the use of the 'typeset' to declare that automatic translation to lowercase characters should be made for any REPLY. This makes' testing for responses short and easy -- no convern for uppercase versus lowercase or mixed case.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 06:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:03 AM
06-19-2003 07:03 AM
Re: Looping a ksh script
I like the different takes on each issue - I will probably use them all in one way or another down the road.
michael - I was looking for the "continue"!.
How simple!
Thanks -
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:06 AM
06-19-2003 07:06 AM
Re: Looping a ksh script
while : ;
do
echo "Display Menu"
resp=*
read resp
case $resp in
[M,m])
cmd
;;
[q,Q])
echo "$program: $exit_code"
exit 0
;;
*)
echo Invalid Responce
sleep 1
;;
esac
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:13 AM
06-19-2003 07:13 AM
Re: Looping a ksh script
I am entering a UID and searching a local file that contains all UIDs,etc:
Top part of script:
#########################
print -n 'User ID to lock ?\n'
read USER
if [[ `/software/master/find_uid.sh "$USER:"` = "" ]];then
print "No accounts available"
return
else
continue
fi
#################
How do I return to re-input a new UID if there is no information in my file?
Thanks again !
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:20 AM
06-19-2003 07:20 AM
Re: Looping a ksh script
"continue" will do it!
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:22 AM
06-19-2003 07:22 AM
Re: Looping a ksh script
continue continues moving through the script - I need to replace the "return" with something that will "start the script over or re-enter the UID.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:35 AM
06-19-2003 07:35 AM
Re: Looping a ksh script
I modified your part to become:
while true;
do
print -n 'User ID to lock ?\n'
read USER
if [[ `/software/master/find_uid.sh "$USER:"` = "" ]];then
print "No accounts available"
continue
else
break
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:36 AM
06-19-2003 07:36 AM
Re: Looping a ksh script
while [ test $RETURN != "yes" ]
do
echo "Display Menu"
resp=*
read resp
case $resp in
[R,r])
run cmd....
exit_code=$?
;;
[C,c])
RETURN="yes"
;;
[q,Q])
echo "$program: $exit_code"
exit 0
;;
*)
echo Invalid Responce
sleep 1
;;
esac
done
I have revised the above code, it continues if "C" or "c" is entered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2003 07:56 AM
06-19-2003 07:56 AM
Re: Looping a ksh script
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 12:49 AM
06-20-2003 12:49 AM
Re: Looping a ksh script
Just an addition.
"continue" is very useful only in loop controls. i.e. when you are using while, for etc... If the statement "continue" is not in a loop, it is equal to not writing the statement itself.
Do not use "continue" frequently in one script as the performance comes down. I read it in some book that in big loops if you are using continue, the internal stack needs to be loaded many times and so the speed comes down. For small loops, you can use it.
Thanks and Regards
VJ.