Matching two Variable in Script

Not applicable

Hi,

I am trying to make Print script for adding printer belonging to particular
floor by Identifying first 3 octets. And then either Self Service or push
the Script with Casper.
I am looking for shortening the script, then entering 2 cases is not
required.
Please Suggest...

1, I have the following script which is too long, where i have to put two
cases for all the printer & script will go long. (this script works but too
long)

#!/bin/sh
# floor is determined by first 3 octet of IP
# run ifconfig enoen1, grab the inet, use AWK to grab the IP address &
remove the periods, and finally
# use awk to grab the 1st,2nd & 3rd octet.

location1=0;
location2=0;

location1=$(ifconfig en0 | grep inet | awk '{print $2}' | awk 'BEGIN
{FS="."} ; {print $1$2$3}');
location2=$(ifconfig en1 | grep inet | awk '{print $2}' | awk 'BEGIN
{FS="."} ; {print $1$2$3}');

echo ${location1};
echo ${location2};

# use the third octet stored in the myFloor1 or myfloor2 variable to
determine which case statement to execute
#en0
case $location1 in floor 27
16677227*) lpadmin -p 1515_27-126_HPCOLORCM8060 -L "1515 27-126" -E -v lpd://
166.77.227.65 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-46_HPCOLORCM8060 -L "1515 27-46" -E -v lpd://
166.77.227.33 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-115_HPM3035xsMFP -L "1515 27-115" -E -v lpd://
172.18.227.28 -P /Library/Printers/PPDs/Contents/Resources/HP LaserJet
M3035 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-64A_HPCOLORCM8060 -L "1515 27-64A" -E -v lpd://
166.77.227.32 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-84_HPLJ4250dtn -L "1515 27-64A" -E -v lpd://
166.77.227.23 -P /Library/Printers/PPDs/Contents/Resources/HP LaserJet
4250.gz -o printer-is-shared=false
echo case1
;;

*)
esac

#en1
case $location2 in floor 27
16677227*) lpadmin -p 1515_27-126_HPCOLORCM8060 -L "1515 27-126" -E -v lpd://
166.77.227.65 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-46_HPCOLORCM8060 -L "1515 27-46" -E -v lpd://
166.77.227.33 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-115_HPM3035xsMFP -L "1515 27-115" -E -v lpd://
172.18.227.28 -P /Library/Printers/PPDs/Contents/Resources/HP LaserJet
M3035 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-64A_HPCOLORCM8060 -L "1515 27-64A" -E -v lpd://
166.77.227.32 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-84_HPLJ4250dtn -L "1515 27-64A" -E -v lpd://
166.77.227.23 -P /Library/Printers/PPDs/Contents/Resources/HP LaserJet
4250.gz -o printer-is-shared=false
echo case2
;;

*)
esac
exit 0;

2, I want to shorten this script in this way, but it doesn't work, for
Matching two variables. here I don't want to add 2 Cases. (this script
doesn't work)

#!/bin/sh
# floor is determined by first 3 octet of IP
# run ifconfig enoen1, grab the inet, use AWK to grab the IP address &
remove the periods, and finally
# use awk to grab the 1st,2nd & 3rd octet.

location1=0;
location2=0;

location1=$(ifconfig en0 | grep inet | awk '{print $2}' | awk 'BEGIN
{FS="."} ; {print $1$2$3}');
location2=$(ifconfig en1 | grep inet | awk '{print $2}' | awk 'BEGIN
{FS="."} ; {print $1$2$3}');

echo ${location1};
echo ${location2};

# use the third octet stored in the myFloor1 or myfloor2 variable to
determine which case statement to execute

case $location1 in
case $location2 in
16677227*) lpadmin -p 1515_27-126_HPCOLORCM8060 -L "1515 27-126" -E -v lpd://
166.77.227.65 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-46_HPCOLORCM8060 -L "1515 27-46" -E -v lpd://
166.77.227.33 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-115_HPM3035xsMFP -L "1515 27-115" -E -v lpd://
172.18.227.28 -P /Library/Printers/PPDs/Contents/Resources/HP LaserJet
M3035 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-64A_HPCOLORCM8060 -L "1515 27-64A" -E -v lpd://
166.77.227.32 -P /Library/Printers/PPDs/Contents/Resources/HP CM8050
CM8060 MFP.gz -o printer-is-shared=false lpadmin -p 1515_27-84_HPLJ4250dtn -L "1515 27-64A" -E -v lpd://
166.77.227.23 -P /Library/Printers/PPDs/Contents/Resources/HP LaserJet
4250.gz -o printer-is-shared=false

;;

*)
esac
exit 0;

Thanks
Kumaresh Kulal

0 REPLIES 0