--- psinib.pl 2003/10/12 18:47:35 1.14 +++ psinib.pl 2003/10/26 12:55:56 1.16 @@ -30,6 +30,9 @@ my $LOG_TIME_FMT = '%Y-%m-%d %H:%M:%S'; # strftime format for logfile my $DIR_TIME_FMT = '%Y%m%d'; # strftime format for backup dir +# define timeout for ping +my $PING_TIMEOUT = 5; + my $LOG = '/var/log/backup.log'; # add path here... #$LOG = '/tmp/backup.log'; @@ -72,13 +75,31 @@ my @in_backup; # shares which are backeduped this run +# init Net::Ping object my $ping; if ($use_ping) { - $ping = new Net::Ping->new("tcp", 2); + $ping = new Net::Ping->new("syn", 2); # ping will try tcp connect to netbios-ssn (139) $ping->{port_num} = getservbyname("netbios-ssn", "tcp"); } +# do syn ping to cifs port +sub host_up { + my $ping = shift || return; + my $host_ip = shift || xlog("host_up didn't get IP"); + my $timeout = shift; + return 1 if (! $use_ping); + + $ping->ping($host_ip,$timeout); + my $return = 0; + + while (my ($host,$rtt,$ip) = $ping->ack) { + xlog("","HOST: $host [$ip] ACKed in $rtt seconds"); + $return = 1 if ($ip eq $host_ip); + } + return $return; +} + my $backup_ok = 0; my $smb; @@ -139,7 +160,7 @@ if ($ip) { xlog($share,"IP is $ip"); - if (($use_ping && $ping->ping($ip)) || 1) { + if (host_up($ping, $ip,$PING_TIMEOUT)) { if (snap_share($share,$user,$passwd,$workgroup)) { $backup_ok++; } @@ -678,6 +699,19 @@ linking same files (other alternative would be to erase that dir and find second-oldest directory, but this seemed like more correct approach). +=head2 I can't connect to any share + +Please verify that nmblookup (which is part of samba package) is in /bin or +/usr/bin. Also verify that nmblookup returns IP address for your server +using: + + $ nmblookup tvhouse + querying tvhouse on 192.168.34.255 + 192.168.34.30 tvhouse<00> + +If you don't get any output, your samba might not listen to correct interface +(see interfaces in smb.conf). + =head1 AUTHOR Dobrica Pavlinusic