in reply to RE: RE: Increment
in thread Increment

I think it's your ++$count that's the problem. The drive numbers are sequential, but you have lines that begin with 'robot'. You don't increment $count for these lines (good) but you do the system command (not so good). Perhaps you should skip out of the loop early if you run into a robot:
next if /^robot/; $count++; system( ... );
Without having anything named 'tpconfig' on my system, I can't check the man page for error messages, but I would be surprised if it allowed you to delete a drive you'd just deleted. The numbers seem to be fairly close.

Update: Here's a more complete code segment that really ought to do it for you:

my $drive; my $count = 0; open( LIST, "tpconfig -l|" ) or die $!; while(<LIST>) { ($drive) = unpack '@0 A8',$_; next unless /^drive/; (system("tpconfig -delete -drive -index ${count}") == 0) or print +"Error deleting: $?"; $count++; }
Starts at 0, doesn't execute the command unless it's found a drive. Increments the number after it executes the command, checks $? for errors. (I'm not 100% certain about the syntax of that system checking, but it was in perlfunc that way.)

Replies are listed 'Best First'.
RE: RE: RE: RE: Increment
by raj8 (Sexton) on Sep 06, 2000 at 06:46 UTC
    The output of $count is still wrong starting at 1 and ending at 34. That will give the tpconfig command a wrong index number and will give errors indicating can't delete drive index. The print of $count is shown below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
RE: RE: RE: RE: Increment
by raj8 (Sexton) on Sep 06, 2000 at 18:37 UTC
    Chromatic, Thanks for the reply, however, it didn't work. But, I used your advice on the next if statement. It appears that when the tpconfig command executes, it puts the header information in there which includes Device, Type and robot. Therefore, the unpack operator picks it up. Therefore, I put multiple next if statements to skip the Device, Type and robot entries. Here is the output of tpconfig command:
    C:\>tpconfig -l Device Robot Drive Robot Drive Device Type Num Index Type DrNum Status Comment Name Path robot 0 - TLD - - - - \\.\Scsi6 +:
    I then used the following to fix the code. If you see a more elegant way of putting multiple next unless statements-- please feel free to flame me. Thanks for your help. The code is shown below:
    sub delete_drives3 { my $drive; $count = -1; open(TPCONFIG,"tpconfig -l|"); while(<TPCONFIG>) { ($drive) = unpack '@0 A5',$_; next if /^r/; next if /^D/; next if /^T/; ++$count; print "Deleting drive $count\n"; system("tpconfig -delete -drive -index ${count}"); }; };