04-05-2007
29,
0
Join Date: Mar 2007
Last Activity: 6 August 2015, 5:50 PM EDT
Location: Tampa, FL
Posts: 29
Thanks Given: 2
Thanked 0 Times in 0 Posts
using case to do this might be a bad idea?
Reading this file. I want to read all 4 fields.
If 2 is populated with a p, I want to set $TYPEP to "Printers",
if not should be empty.
If 3 is populated with an r, I want to set $TYPER to "REQ Printers"
if not should be empty.
If 4 is populated with letter o, I want to set $TYPEO to "Orders"
if not should be empty.
The problem I am having is that it looks like case only lets me fall through it once. I canot get $TYPEP $TYPER $TYPEO to reset to empty after reading each record.
Here is snippet of my file, code and output.
======
Here is snippet of my file:
=======
100:::o:
51:p:r::
52:p:r::
53:p:r::
note: my preview of snippet of the file is showing smiles. Maybe we can start a new thing, smile separated values? :cool: (Just kidding!) Not sure how to get rid of that but it is just 4 colon separated fields, 4 records
I replace colons with commas so you can read it correctly:
100,,,o,
51,p,r,,
52,p,r,,
53,p,r,,
=======
code
=======
############
doIt ()
{
echo "Starting Time:" $RTIME
echo "Cycling Servers In Domain: " ${DOMAIN}
echo ${CYCLER}
echo "Reading server List .. for domain " ${DOMAIN}
echo " Reason"
echo " P=Printers"
echo " R=Requisition Printers"
echo "Server O=Orders"
echo "ID Description P R O Node Domain"
typeset -L36 NM_SERVER
typeset -L9 TYPEP
typeset -L16 TYPER
typeset -L10 TYPEO
while read no pflag rflag oflag
do
NM_SERVER=`$GET_NM -getp \\\node\\\\$NODE_NAME\\\domain\\\\$DOMAIN\\\servers\\\\$no\\\ ServerName`
case ${pflag} in p)
TYPEP="Printers"
;;
esac
case ${rflag} in r)
TYPER="REQ Printers"
;;
esac
case ${oflag} in o)
TYPEO="Orders"
;;
esac
typeset -L4 no
typeset -L10 NODE_NAME
typeset -L6 DOMAIN
typeset -L2 pflag
typeset -L2 rflag
typeset -L2 oflag
printf ${no}${NM_SERVER}${TYPEP}${TYPER}${TYPEO}${pflag}${rflag}${oflag}${NODE_NAME}$DOMAIN
#${CYCLER} ${no} ${NODE_NAME} "-l" ${UN} ${DOMAIN} ${PW}
printf "\n"
unset no
typeset -L2 oflag
typeset -L8 NODE_NAME
typeset -L5 DOMAIN
done< ${FILE_PATH}/.${NODE_NAME}.${DOMAIN}.server.lst | tee -a $LOG
}
########
#MAIN
#######
doIt
======
Output
======
ID Description P R O Node Domain
100 ORM Format Server Orders o cerntst1 build
51 CPM Script Orders p r cerntst1 build
52 CPM Code Cache Manager Orders p r cerntst1 build
53 CPM Script Private Orders p r cerntst1 build
====
My Comments
=====
using ksh on AIX 5.3 ML04
You see thar "Orders" prints for each of the 4 lines. It should have only printed for the first. The other 3 should have printed both "Printers" and REQ Printers"
Any suggestion is appreciated. I think I am using the wrong tool. If you can point me to a more suitable function or command or tool, I appreciate it.
SkyyBugg
=====
Last edited by reborg; 04-05-2007 at 05:29 PM..