Computing.Net > Forums > Unix > ksh/sh cleverness

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ksh/sh cleverness

Reply to Message Icon

Name: destruktobot
Date: August 26, 2003 at 15:44:42 Pacific
OS: aix
CPU/Ram: dunno
Comment:

heya,

i've got this script that controls traffic between two boxes with simple iptables statements. it's good when we want to take one site down for testing, but leave the other one up for production stuffs.

each of these boxes holds a handful of sites, and we have a couple of scripts in each site. i figure that there has to be away to make a "meta script"- a menu that serves up a list of site names and, based on the response, performs those scripts, with all the pertinent info for that site stored in a config file.

unfortunately, i haven't done that much scripting. i have my config file written up that has one site per line:

url,ip,sitename,foo...
url,ip,sitename,foo...
url,ip,sitename,foo...

concatenating this config and cutting makes it easy to display a list of sites, and i follow it with a prompt: what site do you want to reroute?

question is, what next? based on that answer, how can i pick the right line from the config file to pass along the required parameters? if i grep -i (lotsa lazy typists out there ;) for that site's name, how do i extract the line number? alternatively, i could number each site and make the user enter that number, but i'm still stuck with grabbing the right line.


any ideas or help would be crazy appreciated.




Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: August 27, 2003 at 04:41:44 Pacific
Reply:

#!/bin/ksh
hostname1 () {
echo "Some meaningful code"
} # END function hostname1
usage () {
echo "Usage $0 hostname"
}

if [ $# -eq 1 ] ; then
case $1 in
hostname1 | hostname2 | hostname3 | hostname4 ) $1 ;;
h | -h | --help ) usage ; exit 0 ;;
* ) echo "Invalid command line option." ; usage; exit 4 ;;
esac
else
usage
fi
PS3='host? '
select host in \
"hostname1 " \
"hostname2 " \
"hostname3 " \
"hostname4 " \
"(Q) Quit " ;
do
case $REPLY in
1 | 2 | 3 | 4 ) $host
;;
q | Q | 5 )
break
;;
* )
print 'invalid'
;;
esac
done


0
Reply to Message Icon

Related Posts

See More


Changing domains and IP a... Blocking Sent Info to Par...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: ksh/sh cleverness

Script not executing www.computing.net/answers/unix/script-not-executing/7194.html

how 2 place script in start up file www.computing.net/answers/unix/how-2-place-script-in-start-up-file/3977.html

Date Conversion www.computing.net/answers/unix/date-conversion/7298.html