Thread Script funktioniert nicht so richtig (2 answers)
Opened by michaelf2050 at 2010-07-14 21:19

michaelf2050
 2010-07-14 21:19
#139802 #139802
User since
2009-11-03
19 Artikel
BenutzerIn
[default_avatar]
Hallo! - danke voerst für eure hilfe -
ich habe folgenden Code geschrieben:
Code: (dl )
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl

use strict;
use warnings;
require "sendmail.pl";

##
### Definitionen
###

my $mailbodyfile = 'D:\\admin\\perl\\temp\\SENDMAIL_BODYFILEZR1.txt';
my $stunden_dir = 'd:\\admin\\tablespace\\stundenreadings';
my @errors;

###
### Prozeduren
###

sub send_mail {
my ($subject_ref, $error_ref) = @_;
### sendmail.pl braucht den Body als File => erstellen
open SENDMAILBODY, '>'.$mailbodyfile or die "Sendmail Bodyfile '$mailbodyfile' kann nicht erstellt werden! ($!)";
print SENDMAILBODY @$error_ref;
close SENDMAILBODY;
sendmail($$subject_ref, $mailbodyfile);
return 0;
}

sub stundenreadings {
if (opendir STUNDENDIR, $stunden_dir) {
foreach my $file (map "$stunden_dir\\$_", grep !/^\./, readdir STUNDENDIR) {
if (open FILE, '<'.$file) {
my $ok = 0;
while (my $file_row = <FILE>) {
if ($file_row =~ /no rows selected/) {
$ok = 1;
last;
}
}
if ($ok == 1) {
next unless /\d+/;
my ($sid) = $file=~/\\([^\\_]+)_/;;
my ($code, $positionx, $positiony)= split ':' , $_;
$code =~ s/ //g;
$positionx =~ s/ *$//;
$positiony =~ s/ *$//;
#print (file $file)\n;
if ($ok == 1) {push @errors, "Alle stundenreadings OK.\n";
}
else {
push @errors, "Maschine '$code' hat kein stundenreading im Betrieb '$sid' in der letzten stunde erhalten
}
close FILE;
} else {
push @errors, "File '$file' konnte nicht geöffnet werden\n";
}
}
closedir STUNDENDIR;
} else {
push @errors, "Verzeichnis '$stunden_dir' konnte nicht geöffnet werden\n";
}
}
}

### Hauptteil
###

&stundenreadings;


my $mail_subject; ### sendmail.pl setzt Win32::NodeName() davor!
if (@errors) {
$mail_subject .= "ZR1_Alertlog_Fehler!!!";
} else {
$mail_subject .= "ZR1_Alertlog_OK";
}

### Informations E-Mail versenden
&send_mail(\$mail_subject,\@errors);
### Programm mit Status 999 beenden, wenn ein Oracle-Fehler gefunden wurde
exit 999 if @errors;

mein Vorhaben ist aus einem sqlerzeugten textfile Daten auszulesen
ich habe beim SQL-SCRIPT Feedback on somit bekomm ich wenn keine Fehler vorhanden sind "no rows selected"
deshalb hab ich auch versucht mir ein unterscript zu bauen, welches mir ein TRUE/FALSE ($ok =1) - jetzt bekomm ich aber beim ausführen des Progs folgende Fehlermeldung:
Code: (dl )
1
2
3
4
5
6
7
8
9
Bareword found where operator expected at d:\admin\perl\scripts\stundenreadings.pl line 55, near "push @errors, "File"
(Might be a runaway multi-line "" string starting on line 51)
(Do you need to predeclare push?)
String found where operator expected at d:\admin\perl\scripts\stundenreadings.pl line 55, near "File '$file'"
(Do you need to predeclare File?)
Bareword found where operator expected at d:\admin\perl\scripts\stundenreadings.pl line 55, near "'$file' konnte"
(Missing operator before konnte?)
syntax error at d:\admin\perl\scripts\stundenreadings.pl line 55, near "push @errors, "File "
Unrecognized character \xF6 at d:\admin\perl\scripts\stundenreadings.pl line 55.

hat jemand eine Idee, was ich falsch gemacht habe?
danke für eure Hilfe
lg
michaelf

View full thread Script funktioniert nicht so richtig