David Sankovsky
asked on
improve Shell script
Hi Guys, I'm trying to improve my Shell script a little.
Basically it's a simple script that uses Zenity to display a form that I can use to RDP to other computers using rdesktop.
What I'd like to achieve is the following... Save previous servers I've visited into a file that Zenity can read from and later on display as a drop down list on the Hostname\IP field (While still accepting manual imput of course)
and I'd like to add a field called Resolution in which I can select from a drop-down list of resolutions in which to run rdesktop.
Original script follows:
Basically it's a simple script that uses Zenity to display a form that I can use to RDP to other computers using rdesktop.
What I'd like to achieve is the following... Save previous servers I've visited into a file that Zenity can read from and later on display as a drop down list on the Hostname\IP field (While still accepting manual imput of course)
and I'd like to add a field called Resolution in which I can select from a drop-down list of resolutions in which to run rdesktop.
Original script follows:
#!/bin/bash
ans=`zenity --width=400 --height=200 --forms --title="Remote desktop client (Windows)" --text="Remote desktop computer" --add-entry="Hostname\IP" --add-entry="Username" --add-entry="Domain" --add-password="Password"`
ip_s=`echo $ans | cut -f1 -d"|"`
user=`echo $ans | cut -f2 -d"|"`
doma=`echo $ans | cut -f3 -d"|"`
pass=`echo $ans | cut -f4 -d"|"`
if [ -z $user ]; then
user='Administrator'
fi
if [ ! $doma ]; then
#echo $user $doma $pass
rdesktop -g1920x1040 -z -u $user -p $pass $ip_s -0 -5 -K -r clipboard:CLIPBOARD
else
rdesktop -g19201040 -z -d $doma -u $user -p $pass $ip_s -0 -5 -K -r clipboard:CLIPBOARD
fi
if [ $? == "76" ]; then
zenity --error --text "Unable to connect !!!"
ASKER
Thanks a lot, that does seem to be a step in the right direction, however, when I use
I run into a problem as the list is till empty.
I need it to be like a combo box, where I can select from a drop down list but also input the IP Address manually
ip_s=`zenity --list --column="Target host" $hosts
I run into a problem as the list is till empty.
I need it to be like a combo box, where I can select from a drop down list but also input the IP Address manually
ASKER
Please see my Current Version.. I need to somehow allow multibox for the IP / Host.
#!/bin/bash
# Display the Zenity window and read the user responses into $ans.
hosts=`cat /scripts/hosts.lst`
ip_s=`zenity --entry --title "Connection Target" --text "Enter the hostname or IP." "${hosts[@]}"`
ans=`zenity --width=400 --height=200 --forms --title="Remote desktop client (Windows)" --text="Remote desktop computer" --add-entry="Username" --add-entry="Domain" --add-password="Password"`
res=`zenity --list --column="Resolution" 1920x1040 1440x900 1280x1024 1024x768`
# Read Answers from Zenity Window into the needed parameters.
user=`echo $ans | cut -f1 -d"|"`
doma=`echo $ans | cut -f2 -d"|"`
pass=`echo $ans | cut -f3 -d"|"`
#Check if IP is in list and if not, save it to the list.
if ! grep -q "^${ip_s}$" /scripts/hosts.lst; then
echo $ip_s >> /scripts/hosts.lst
sort -u /scripts/hosts.lst > /tmp/h && mv -f /tmp/h /scripts/hosts.lst
fi
# Assume user Administrator if no user specified
if [ -z $user ]; then
user='Administrator'
fi
#Initiate the rdesktop session based on the recieved Parameters.
if [ ! $doma ]; then
# If domain is not specified, do not pass the parameter to rdesktop
rdesktop -g$res -z -u $user -p $pass $ip_s -0 -5 -K -r clipboard:CLIPBOARD
else
# If domain is specified, pass the parameter to rdesktop
rdesktop -g$res -z -d $doma -u $user -p $pass $ip_s -0 -5 -K -r clipboard:CLIPBOARD
fi
if [ $? == "76" ]; then
zenity --error --text "Unable to connect !!!"
fi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got me going in the right direction. Thanks
What you may have to do is ask the questions one by one. For the resolutions, pass them as separate parameters on the command line, such as
res=`zenity --list --column="Resolution" 1600x1200 1280x1024 1024x768`
and it will pass back the selected item
For the IP addresses (or host names), do something like
hosts=`cat /path/to/saved/hosts.lst`
ip_s=`zenity --list --column="Target host" $hosts
(assumes that the hosts don't have any spaces in them - they shouldn't have!)
then add the new Ip to the hosts file if not already there, and sort into order.
if ! grep -q "^${ip_s}$" /path/to/saved/hosts.lst; then
echo $ip_s >> /path/to/saved/hosts.lst
sort -u /path/to/saved/hosts.lst > /tmp/h && mv -f /tmp/h /path/to/saved/hosts.lst
fi