
Please click the above image for a larger, and scarier, version ;)
Hello again,
Just in case you read the title and thought "oh man, more color?", I've kept it to a minimum here ;) Although the concepts used in creating today's script were covered in our previous posts on using color in the shell and creating a simple color menu (both for Linux and Unix), this one is just different enough that I thought it might be of interest to some folks out there.
Today's script is actually for a very specific brand of Linux: Cygwin for Windows XP (I think you could get away with using this script letter-for-letter on Windows 2000, but I can't be sure about ME and Vista).
The script interface is designed so that you can access the Windows Control Panel directly from your default Cygwin Bash shell. Check out the picture above for a look at it in action (breathtaking... ;). Unfortunately, I have yet to figure out how to make Cygwin control the Control Panel applets once they've launched in Windows. I believe it might be possible with some Tk button pushing, but that's beyond where I'm at with Cygwin.
The script can be run simply from the command line and requires no arguments (Although it does assume that your Windows environment is setup correctly and your system knows where its system32 folder is):
user@hostpc ~ ./xpcpanel.sh
You'll note that not every single control panel option is included in our Linux menu shell script. I picked the top 16 (This is a subjective rating system of course ;). All of the other applets should be listed under your main Windows directory, in the system32 folder and named something like "applet.cpl". For instance, the output from an "ls" on my machine comes out to around 30 applets. They can all be run using the "control" command, like so:
user@hostpc ~ control main.cpl
And here's the complete list of applets you can use to customize this menu (The number and availability may vary depending on your system, but this should be a fair representation. Also note that /cygdrive/c/WINDOWS/system32 directory is actually C:\WINDOWS\system32 if you use Windows to navigate):
user@hostpc ~
$ ls /cygdrive/c/WINDOWS/system32/*.cpl
/cygdrive/c/WINDOWS/system32/access.cpl
/cygdrive/c/WINDOWS/system32/appwiz.cpl
/cygdrive/c/WINDOWS/system32/bthprops.cpl
/cygdrive/c/WINDOWS/system32/desk.cpl
/cygdrive/c/WINDOWS/system32/firewall.cpl
/cygdrive/c/WINDOWS/system32/hdwwiz.cpl
/cygdrive/c/WINDOWS/system32/inetcpl.cpl
/cygdrive/c/WINDOWS/system32/infocardcpl.cpl
/cygdrive/c/WINDOWS/system32/intl.cpl
/cygdrive/c/WINDOWS/system32/irprops.cpl
/cygdrive/c/WINDOWS/system32/javacpl.cpl
/cygdrive/c/WINDOWS/system32/joy.cpl
/cygdrive/c/WINDOWS/system32/main.cpl
/cygdrive/c/WINDOWS/system32/mlcfg32.cpl
/cygdrive/c/WINDOWS/system32/mmsys.cpl
/cygdrive/c/WINDOWS/system32/nCredps.cpl
/cygdrive/c/WINDOWS/system32/ncpa.cpl
/cygdrive/c/WINDOWS/system32/netsetup.cpl
/cygdrive/c/WINDOWS/system32/nusrmgr.cpl
/cygdrive/c/WINDOWS/system32/nwc.cpl
/cygdrive/c/WINDOWS/system32/odbccp32.cpl
/cygdrive/c/WINDOWS/system32/powercfg.cpl
/cygdrive/c/WINDOWS/system32/sapcacpl.cpl
/cygdrive/c/WINDOWS/system32/sapfcpl.cpl
/cygdrive/c/WINDOWS/system32/sysdm.cpl
/cygdrive/c/WINDOWS/system32/telephon.cpl
/cygdrive/c/WINDOWS/system32/timedate.cpl
/cygdrive/c/WINDOWS/system32/wgpocpl.cpl
/cygdrive/c/WINDOWS/system32/wscui.cpl
/cygdrive/c/WINDOWS/system32/wuaucpl.cpl
And here it is. I hope you enjoy it and find it useful. Once I'm on the Linux command line, I don't want to futz around with Windows unless I have to, and this script helps out a little :)
And, oh yes, note also that this is a fairly long menu (16 control panel items alone), so the default Cygwin window won't be big enough to fit it all in. As long as you enter a value (it can even be bogus) and hit any key, it will redraw the screen so you can resize your window as many times as you want)
Cheers,
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License#!/bin/bash
#
# xpcpanel.sh - Save Yourself The Hassle Of Dealing With The XP Start Menu :)
#
# 2008 - Mike Golvach - eggi@comcast.net
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#
trap 'tput reset;exit 1' 1 2 3 9 15
tput civis
while :
do
echo -e "\033[44;37;22m"
clear
echo -e "\033[41;37m"
echo -ne "\033[46;30m"
tput cup 8 25 ; echo -n " Windows XP Control Panel "
tput cup 9 25 ; echo -n "----------------------------"
tput cup 10 25 ; echo -n " Choose Your Option "
echo -e "\033[40;32m"
tput cup 12 25 ; echo -n " 1. Accessibility "
tput cup 13 25 ; echo -n " 2. Add/Remove Programs "
tput cup 14 25 ; echo -n " 3. Display Settings "
tput cup 15 25 ; echo -n " 4. Add Hardware "
tput cup 16 25 ; echo -n " 5. Internet Explorer Setup "
tput cup 17 25 ; echo -n " 6. Regional Settings "
tput cup 18 25 ; echo -n " 7. Game Controllers "
tput cup 19 25 ; echo -n " 8. Mouse Settings "
tput cup 20 25 ; echo -n " 9. Keyboard Settings "
tput cup 21 25 ; echo -n " 10. Sound/Audio Settings "
tput cup 22 25 ; echo -n " 11. Network Settings "
tput cup 23 25 ; echo -n " 12. User Account Settings "
tput cup 24 25 ; echo -n " 13. Power Settings "
tput cup 25 25 ; echo -n " 14. System Properties "
tput cup 26 25 ; echo -n " 15. Phone And Modem Options"
tput cup 27 25 ; echo -n " 16. Date/Time Settings "
tput cup 28 25 ; echo -n " 17. Quit "
echo -ne "\033[41;30m"
tput cup 30 28 ; echo -n " Pick Your Poison: "
tput cup 30 48
tput sc
read y
tput cup 32 30
case "$y" in
1)
control access.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
2)
control appwiz.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
3)
control desk.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
4)
control hdwwiz.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
5)
control inetcpl.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
6)
control intl.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
7)
control joy.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
8)
control main.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
9)
control main.cpl,@1
tput rc
echo -n "Any Key To Menu"
read x
;;
10)
control mmsys.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
11)
control ncpa.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
12)
control nusrmgr.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
13)
control powercfg.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
14)
control sysdm.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
15)
control telephon.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
16)
control timedate.cpl
tput rc
echo -n "Any Key To Menu"
read x
;;
17|q|Q)
tput sgr0
clear
exit
;;
[A-Za-z])
tput cup 32 28
echo "Unless you're quitting, please Pick a NUMBER"
tput rc
echo -n "Any Key To Menu"
read x
;;
*)
tput cup 32 28
echo "$y - Unknown Option"
tput rc
echo -n "Any Key To Menu"
read x
;;
esac
done
, Mike
linux unix internet technology
Wednesday, April 9, 2008
Shell Menu Script For Cygwin Linux To Access The XP Control Panel
Tuesday, April 1, 2008
Script For A Simple Menu Using Tput And ANSI Color

Click above to see a larger example of what happens when you dare to select option 1 ;)
Hey there,
Today I thought we'd look at something that almost all admins have to do at some point or another; create a simple shell menu script for users who aren't Unix or Linux savvy, but need to make use of the systems directly, nonetheless.
To spice it up (a little. There's only so much you can do ;) I've used colors within the standard shell menu framework, sticking with the ECMA compliant ANSI color codes. The reason I choose to stand by these color codes (since they, admittedly, lack the range of colors available in different flavors of Linux and Unix) is that they're virtually guaranteed to work on "all" flavors of Linux and Unix. Or maybe I'm just a people pleaser who hasn't realized that he can't win 'em all yet ;)
You'll notice also that, rather than just throw the menu together, using "case" inside a "select" loop, I went out of my way to complicate things by using tput to manage the cursor on the screen. In this case, it actually adds some functionality to the menu that would, otherwise, be impossible to implement. I shied away from unnecessarily using "getopts" when our "case" statement can handle these simple menu arguments just as efficiently :).
You can run this menu very simply, from the command line, like so:
host # ./SimpleMenu.sh
And there are only a few things to really take note of today. In a future post, I'll devote more time to utilizing your terminal screen with tput. It can be used to do a lot more useful, and entertaining, things than what we're having it do today.
Basically, in quick sequential order, we're using tput to:
1. Make the cursor invisible : tput civis
2. Position the cursor at various places on the terminal: tput cup x y <--- With x and y being single numeric coordinates designating the row and column, respectively.
3. Save the current cursor position: tput sc
4. Get back to (recover) the previously saved cursor position: tput rc
5. Make everything go back to the way it was, just in case our screen gets screwed up: tput reset
You can also, very simply, modify this shell menu script by just changing the menu options and adding your own routines to the case loop. And, if you can find something less offensive to your sensibilities, please do change the color scheme ;)
Enjoy :)
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License#!/bin/bash
#
# SimpleMenu.sh - Only SomeWhat Useful ;)
#
# 2008 - Mike Golvach - eggi@comcast.net
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#
trap 'tput reset;exit 1' 1 2 3 9 15
tput civis
while :
do
echo -e "\033[44;37;22m"
clear
echo -e "\033[41;37"
echo -ne "\033[46;30m"
tput cup 8 25 ; echo -n "The Linux and Unix Menagerie"
tput cup 9 25 ; echo -n " Shell Account Services "
tput cup 10 25 ; echo -n " W E L C O M E "
echo -e "\033[40;32m"
tput cup 12 25 ; echo -n " 1. See Who's Logged In "
tput cup 13 25 ; echo -n " 2. Reboot The Server "
tput cup 14 25 ; echo -n " 3. Gain Root Access "
tput cup 15 25 ; echo -n " 4. Call Your Mother "
tput cup 16 25 ; echo -n " 5. Quit "
echo -ne "\033[41;30m"
tput cup 18 28 ; echo -n " Pick Your Poison: "
tput cup 18 48
tput sc
read y
tput cup 20 30
case "$y" in
1|S|s)
output=`w|awk '{print $1}' |xargs -ibing grep bing /etc/passwd|awk -F":" '{print $5}'`
starting_line=21
tput cup $starting_line 28;
echo -ne "\033[46;30mCurrently Logged In Users:"
echo -ne "\033[0m"
echo "$output"|while read x
do
let starting_line=$starting_line+1
tput cup $starting_line 28;
echo -n $x
done
tput rc
echo -n "Any Key To Menu"
read x
;;
2|R|r)
tput cup $starting_line 28;
echo -n "Option Not Active Yet"
tput rc
echo -n "Any Key To Menu"
read x
;;
3|G|g)
tput cup $starting_line 28;
echo -n "Option Not Active Yet"
tput rc
echo -n "Any Key To Menu"
read x
;;
4|C|c)
tput cup $starting_line 28;
echo -n "Option Not Active Yet"
tput rc
echo -n "Any Key To Menu"
read x
;;
5|Q|q)
tput reset
clear
exit
;;
*)
tput cup 20 28
echo "$y - Unknown Option"
tput rc
echo -n "Any Key To Menu"
read x
;;
esac
done
, Mike
linux unix internet technology





