Sponsored Content
Top Forums Shell Programming and Scripting Deletion and recreation within a script Post 302434310 by ggoliath on Friday 2nd of July 2010 05:57:51 AM
Old 07-02-2010
Deletion and recreation within a script

  • All printers are created on the PROD server and my script must pick up the differences in a diffs.txt file
  • delete the printer if exist on the DEV server
  • recreate it as it currently stands on the PROD server from the diffs.txt
The following script I have, should allow me in synching the local server printers with the remote server's printers.
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 'NR==FNR{ arr[$3]=$0; next} $3 in arr { delete arr[$3]; next} { print } END {
 for (i in arr) print arr[i] }' sun5-printers.txt 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
   [ -z "${prt}" ] && continue
   echo "\n\t Deleting printer ${prt} !!!"
   if ! $BIN/lpadmin -x ${prt} 2> /dev/null
   then
       echo " Failed to delete printer !!"
       continue
   fi
   echo "Printer ${prt} DELETED!"
   echo "Adding Printer $prt !!!!"
   if ! $BIN/lpadmin -p ${prt} -E -v ${drv}://${IP}:${port}
   then
       echo "Failed to add printers !!!"
       continue
   fi
   echo "\n\t Printer $prt:$drv://$IP:$port created"
done < diffs.txt

Problem experiencing is that its not re-creating the printers as it is on the PROD server.
Is there something amiss that its not re-creating the printers..help will be much appreciated.Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for automatic deletion of old files

Hi, I have a folder with limited space. I do not have provisions to increase the space for this folder. So i have to delete files which are more than 1 month old automatically. But, i need to maintain the files created by 4 users and delete all the other files automatically which is more than 1... (4 Replies)
Discussion started by: vivek_scv
4 Replies

2. Solaris

Script for automatic deletion of trash file of mail server

Hi, I have a mail server with limited space and operating system is sun solaris 8 (sparc). I do not have provisions to increase the space for home directory. So i have to delete files from /home/username/mail/trash which are more than 10 days old automatically. So my script should be like... (1 Reply)
Discussion started by: crown2100bd
1 Replies

3. UNIX for Dummies Questions & Answers

script for deletion using wildcards

find ./ -name t\* | sed "s@^./@@" > .filestobedeleted j=$(wc -l < .filestobedeleted) typeset -i cnt=0 typeset -i i=0 while read line do myarray=$line ((cnt = cnt + 1)) done < .filestobedeleted while (1 Reply)
Discussion started by: aishu
1 Replies

4. Solaris

Script for automatic deletion of old folder

Hi, I have a folder with limited space. So i have to delete folder which are more than 5 days old automatically. So my script should be like delete the folder more than 5 days old. Can someone help me to generate a script for this. Thank you... Cheer Summer (5 Replies)
Discussion started by: summerpeh
5 Replies

5. HP-UX

User Recreation | Urgent Help Needed

Hi, I've mistakenly removed user id from HP Unix server. I've removed using SAM Now i need to resotre/recreat the removed user id (with same uid,group and username), How can i do that. Thanks in Advance (3 Replies)
Discussion started by: msgobinathan
3 Replies

6. Shell Programming and Scripting

Dynamic Log Deletion/Rotatoin Script

I've written a small static script for my log deletion, but I was wondering if there was a way to make it a dynamic script. here is how my script currently works. #!/bin/sh ########################################### #Script to zip logs older than 1 week old #and to delete logs older than 30... (3 Replies)
Discussion started by: cbo0485
3 Replies

7. Shell Programming and Scripting

Unique Directory and Folder Deletion Script

Ok, so I just got charged with the task of deleting some 300 user folders in a FTP server to free up some space. I managed to grep and cut the list of user folders to delete into a list of one user folder per line. Example: bob00 jane01 sue03 In the home folder, there are folders a-z, and... (5 Replies)
Discussion started by: b4sher
5 Replies

8. Shell Programming and Scripting

file and directory deletion script

I saw many post about this but could not find a specific answer to this question. i have the following code find . -depth -name "$FILEEXT" -ctime -30 -exec rm {} \; when i type ./deletefiles.sh *.txt for example, it will find all the txt files less than 30 days old and delete them. my... (9 Replies)
Discussion started by: new2learn09
9 Replies

9. Post Here to Contact Site Administrators and Moderators

Post deletion

Admin: I've had posted twice my last post Can you please delete it from the SCO forum=? thanks (1 Reply)
Discussion started by: funyotros
1 Replies

10. AIX

Recreation of Volume Group

Hi, I am having 2 volume groups rootvg (Only for os),datavg(only for data) both are from san using different LUN. out of these my rootvg was crashed though I have reinstalled os. can you please suggest me now how datavg will be visible, wheather I have recreate VG? Kindly suggest me. (5 Replies)
Discussion started by: manoj.solaris
5 Replies
enable(1)                                                          User Commands                                                         enable(1)

NAME
enable, disable - enable/disable LP printers SYNOPSIS
/usr/bin/enable printer... /usr/bin/disable [-c | -W] [ -r [reason]] printer... DESCRIPTION
The enable command activates printers, enabling them to print requests submitted by the lp command. enable must be run on the printer server. The disable command deactivates printers, disabling them from printing requests submitted by the lp command. By default, any requests that are currently printing on printer will be reprinted in their entirety either on printer or another member of the same class of printers. The disable command must be run on the print server. Use lpstat -p to check the status of printers. enable and disable only effect queueing on the print server's spooling system. Executing these commands from a client system will have no effect on the server. OPTIONS
The following options are supported for use with disable: -c Cancels any requests that are currently printing on printer. This option cannot be used with the -W option. If the printer is remote, the -c option will be silently ignored. -W Waits until the request currently being printed is finished before disabling printer. This option cannot be used with the -c option. If the printer is remote, the -W option will be silently ignored. -r [reason] Assigns a reason for the disabling of the printer(s). This reason applies to all printers specified. This reason is reported by lpstat -p. Enclose reason in quotes if it contains blanks. The default reason is "unknown reason" for the existing printer, and "new printer" for a printer added to the system but not yet enabled. OPERANDS
The following operand is supported for both enable and disable: printer The name of the printer to be enabled or disabled. Specify printer using atomic name. See printers.conf(4) for information regarding the naming conventions for atomic names. EXIT STATUS
The following exit values are returned: 0 Successful completion. non-zero An error occurred. FILES
/var/spool/lp/* LP print queue. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWpcu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ SEE ALSO
lp(1), lpstat(1), printers.conf(4), attributes(5) SunOS 5.10 9 Sep 1996 enable(1)
All times are GMT -4. The time now is 08:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy