Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two scripts must be combined into one

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
how can i combine the following two scripts into one:
Code:
#!/bin/ksh
BIN=/usr/lbin
LINE='device for 0101a01: lpd://172.25.41.111:515'
while read LINE
do
prt=`echo $LINE | awk '{print $3 }'| cut -c 1-7`
echo $prt
#drv=`echo $LINE | awk -F":" '{print $2}'`
#echo $drv
#IP=`echo $LINE | awk -F"/" '{print $3}' | cut -d":" -f1`
#echo $IP
#port=`echo $LINE | awk -F":" '{print $4}'`
#echo $port
  if [ "${prt}" = "0117bd1" ]; then

     echo "\n\t Deleting printer $prt  !!!"

     $BIN/lpadmin -x ${prt} 2> /dev/null
  fi
done < diffs.txt

second script:
Code:
#!/bin/ksh -xv
BIN=/usr/lbin
LINE='device for 0101a01: lpd://172.25.41.111:515'
while read LINE
do
prt=`echo $LINE | awk '{print $3 }' | cut -c 1-7`
echo $prt
drv=`echo $LINE | awk -F":" '{print $2}'`
echo $drv
IP=`echo $LINE | awk -F"/" '{print $3}' | cut -d":" -f1`
echo $IP
port=`echo $LINE | awk -F":" '{print $4}'`
echo $port
  if [ "${prt}" = "0117bd1" ]; then

        echo " Adding printer $prt !!!!"

        $BIN/lpadmin -p ${prt} -E -v ${drv}://${IP}:${port}

        echo " Printer $prt:$drv:$IP:$port added!!!!"
  fi
done< diffs.txt

here i deleted a printer name and recreated printer
 
Code:
cat script1.sh script2.sh | sort > total_mess.sh
In other words, you need to give a little more detail on what you're trying to accomplish.


 
the first script does a delete, the second script a recreate...both scripts have the same variables, read from the same file.
I would like one script that can do both, delete and recreate...
 
Ok guys, i figured out how to delete and re-create one printer from my text file...with the following script
Code:
#!/bin/ksh
BIN=/usr/lbin
LOCAL_FILE=`$BIN/lpstat -v > sun5-printers.txt`
REMOTE_FILE=`rsh sun8 /usr/lbin/lpstat -v > sun8-printers.txt`
#DIFF_FILE=/usr/local/bin/diffs.txt

awk 'BEGIN {while ( getline < "sun5-printers.txt") {arr[$0]++ } } { if (!($0 in a
rr ) ) { print } }' sun8-printers.txt > diffs.txt

LINE='device for 0101a01: lpd://172.25.41.111:515'
while read LINE
do
  prt=`echo $LINE | awk '{print $3 }'| cut -c 1-7`
    echo $prt
  drv=`echo $LINE | awk -F":" '{print $2}'`
    echo $drv
  IP=`echo $LINE | awk -F"/" '{print $3}' | cut -d":" -f1`
    echo $IP
  port=`echo $LINE | awk -F":" '{print $4}'`
    echo $port

#Delete or Create Printer

   if [ "${prt}" = "2201bl4" ]; then

         echo "\n\t Deleting printer ${prt} !!!"

         $BIN/lpadmin -x ${prt} 2> /dev/null
   fi

   if [ "${prt}" = "2201bl4" ];then

         echo "\n\t Adding printers $prt !!!!"

         $BIN/lpadmin -p ${prt} -E -v ${drv}://${IP}:${port}

         echo "\n\t Printer $prt:$drv:$IP:$port created"
   fi

done < diffs.txt

BUT i need it to be done for all printers within my text file, which has three printers.WHAT DO I CHANGE IN MY SCRIPT, THAT WILL MAKE CHANGES TO EVERYTHING WITHIN THE TEXT FILE?????
 
Why do you have this line?

Code:
if [ "${prt}" = "2201bl4" ]; then

Annihilannic.
 
was to select a certain printer from my text file in order to delete just the 1 printer and to recreate the same printer
 
So... if you want to do all of the printers in the file... just take it out?

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top