unless ( $status == (1 || 2) ) {
print "\nport status must be either up or down\n\n";
exit;
} else {
system("/usr/bin/snmpset hostname password
interfaces.ifTable.ifEntry.ifAdminStatus.$port i $status");
}
Your commented lines were not woking because you were checking using the
character not numeric operators (ne instead of !=). Also you had the logic
saying "If status doesn't equal 1 fail. Or if status doesn't equal 2, fail".
If status was 1, it would still fail as you have the "or if status doesn't
equal 2" kicking in. If status was 2, it would still fail because it didn't
equal 1.
The above says "unless status equals 1 or 2, fail", which is what you need.
HTH
John
-----Original Message-----
From: dan radom [mailto:[EMAIL PROTECTED]]
Sent: 03 September 2001 17:00
To: [EMAIL PROTECTED]
Subject: why doesn't this work
I'm very new to perl. I have been trying to reweite some of my shell scripts
to learn the language. Here's what I've got...
#!/usr/local/bin/perl -w
if ( $#ARGV+1 !=2 ) {
print "\n";
print "usage cat.pl port up\/down\n";
print "\n";
exit;
}
chomp( $port = $ARGV[0] );
chomp( $ARGV[1] );
if ( $ARGV[1]=~/up/i ) { $status = 1; } elsif ( $ARGV[1]=~/down/i ) {
$status=2 };
print "$status";
#if (( $status ne 1 ) || ( $status ne 2 )) {
# print "\n";
# print "port status must be either up or down\n";
# print "\n";
# exit;
#}
system("/usr/bin/snmpset hostname password
interfaces.ifTable.ifEntry.ifAdminStatus.$port i $status");
Here is the output fro mthe script...
lunar:~/bin$ cat.pl 1 down
2
port status must be either up or down
It never makes the system call to snmpget.
The commented lines is what isn't working. Up to "print "$status";"
everything is fine and the appropriate status returns. I need the script to
exit if $status doesn't equal 1 or 2. If $status does the ni need it to
continue and make the system call to snmpset.
Thanks in advance,
dan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------Confidentiality--------------------------.
This E-mail is confidential. It should not be read, copied, disclosed or
used by any person other than the intended recipient. Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful. If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]