Bonjour, j ai un souci avec mon fork.
Je dois stocker des ip et ensuite envoyer un mail recapitulant les ip repondant au ping mais je ne vois pas comment faire
si vous pouviez me donner un petit coup de main sa serait super
Merci d'avance
Je vous mets mon code source:
Ce code fait appel a ce code la pour l'envoie de mail
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #!/usr/bin/perl -w use strict; use Net::Ping; use Mail::Sendmail; my @cam = ("192.168.1.150","192.168.1.151","192.168.1.152","192.168.1.153","192.168.1.154","192.168.1.155","192.168.1.156","192.168.1.157","192.168.1.158","192.168.1.159","192.168.1.59"); my $p = Net::Ping->new("icmp"); my $chemin = "./pingE.pl"; my @pids; sub lancePing($) { my ($ip) = @_; die("problème de fork !!!!\n"), unless defined(my $pid = fork()); if ($pid == 0) { # c'est le fils ! on execute la commande system($chemin, $ip); # et après, on sort exit; } else { # c'est le père, on n'attend pas le fils, on continue ! on stocke juste le pid push(@pids, $pid); } } # on lance le prog en parallèle foreach my $ip (@cam){ &lancePing($ip); } # suite du code, executée immédiatement # sub appelée automatiquement en fin de programme END { # on attend la fin des fils foreach my $pid(@pids) { waitpid($pid, 0); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #!/usr/bin/perl -w use strict; use Net::Ping; use Mail::Sendmail; my $p = Net::Ping->new("icmp"); my $chemin = "./pingE.pl"; my $ipE=$ARGV[0]; print $ipE; if ($p->ping("$ipE")) { my %mail = ( To => "\@blalba", From => "camera ".$ipE."\@blabla", Subject => "Test Camera ".$ipE." Pb", Message => $ipE ." repond au Ping!.\n" ); if (sendmail %mail) { print "Mail sent OK ". $ipE.".\n" } else { print "Error sending mail: $Mail::Sendmail::error \n" } } else { my %mail = ( To => "\@blalba", From => "camera ".$ipE."\@blabla", Subject => "Test Camera ".$ipE." Pb", Message => $ipE ." ne repond pas au Ping, il y a un probleme !.\n" ); if (sendmail %mail) { print "Mail sent OK ". $ipE.".\n" } else { print "Error sending mail: $Mail::Sendmail::error \n" } sleep(1800); system($chemin, $ipE); }
Partager