/[psinib]/psinib.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /psinib.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by dpavlin, Sun Oct 12 17:44:21 2003 UTC revision 1.16 by dpavlin, Sun Oct 26 12:55:56 2003 UTC
# Line 24  use Filesys::SmbClient; Line 24  use Filesys::SmbClient;
24  use Fcntl qw(LOCK_EX LOCK_NB);  use Fcntl qw(LOCK_EX LOCK_NB);
25  use Digest::MD5;  use Digest::MD5;
26  use File::Basename;  use File::Basename;
27    use Getopt::Long;
28    
29  # configuration  # configuration
30  my $LOG_TIME_FMT = '%Y-%m-%d %H:%M:%S'; # strftime format for logfile  my $LOG_TIME_FMT = '%Y-%m-%d %H:%M:%S'; # strftime format for logfile
31  my $DIR_TIME_FMT = '%Y%m%d';            # strftime format for backup dir  my $DIR_TIME_FMT = '%Y%m%d';            # strftime format for backup dir
32    
33    # define timeout for ping
34    my $PING_TIMEOUT = 5;
35    
36  my $LOG = '/var/log/backup.log';        # add path here...  my $LOG = '/var/log/backup.log';        # add path here...
37  #$LOG = '/tmp/backup.log';  #$LOG = '/tmp/backup.log';
38    
# Line 58  my $c = 0; Line 62  my $c = 0;
62  # taint path: nmblookup should be there!  # taint path: nmblookup should be there!
63  $ENV{'PATH'} = "/usr/bin:/bin";  $ENV{'PATH'} = "/usr/bin:/bin";
64    
65    my $use_ping = 1;       # deault: use ping to verify that host is up
66    
67    my $result = GetOptions(
68            "ping!" => \$use_ping, "backupdest!" => \$BACKUP_DEST,
69    );
70    
71  my $mounts = shift @ARGV ||  my $mounts = shift @ARGV ||
72          'mountscript';          'mountscript';
73  #       die "usage: $0 mountscript";  #       die "usage: $0 mountscript";
# Line 65  my $mounts = shift @ARGV || Line 75  my $mounts = shift @ARGV ||
75    
76  my @in_backup;  # shares which are backeduped this run  my @in_backup;  # shares which are backeduped this run
77    
78  my $p = new Net::Ping->new("tcp", 2);  # init Net::Ping object
79  # ping will try tcp connect to netbios-ssn (139)  my $ping;
80  $p->{port_num} = getservbyname("netbios-ssn", "tcp");  if ($use_ping) {
81            $ping = new Net::Ping->new("syn", 2);
82            # ping will try tcp connect to netbios-ssn (139)
83            $ping->{port_num} = getservbyname("netbios-ssn", "tcp");
84    }
85    
86    # do syn ping to cifs port
87    sub host_up {
88            my $ping = shift || return;
89            my $host_ip = shift || xlog("host_up didn't get IP");
90            my $timeout = shift;
91            return 1 if (! $use_ping);
92    
93            $ping->ping($host_ip,$timeout);
94            my $return = 0;
95    
96            while (my ($host,$rtt,$ip) = $ping->ack) {
97                    xlog("","HOST: $host [$ip] ACKed in $rtt seconds");
98                    $return = 1 if ($ip eq $host_ip);
99            }
100            return $return;
101    }
102    
103  my $backup_ok = 0;  my $backup_ok = 0;
104    
# Line 129  while(<M>) { Line 160  while(<M>) {
160    
161          if ($ip) {          if ($ip) {
162                  xlog($share,"IP is $ip");                  xlog($share,"IP is $ip");
163                  if ($p->ping($ip)) {                  if (host_up($ping, $ip,$PING_TIMEOUT)) {
164                          if (snap_share($share,$user,$passwd,$workgroup)) {                          if (snap_share($share,$user,$passwd,$workgroup)) {
165                                  $backup_ok++;                                  $backup_ok++;
166                          }                          }
# Line 668  be renamed to I<YYYYMMDD.partial> and sn Line 699  be renamed to I<YYYYMMDD.partial> and sn
699  linking same files (other alternative would be to erase that dir and find  linking same files (other alternative would be to erase that dir and find
700  second-oldest directory, but this seemed like more correct approach).  second-oldest directory, but this seemed like more correct approach).
701    
702    =head2 I can't connect to any share
703    
704    Please verify that nmblookup (which is part of samba package) is in /bin or
705    /usr/bin. Also verify that nmblookup returns IP address for your server
706    using:
707    
708       $ nmblookup tvhouse
709       querying tvhouse on 192.168.34.255
710       192.168.34.30 tvhouse<00>
711    
712    If you don't get any output, your samba might not listen to correct interface
713    (see interfaces in smb.conf).
714    
715  =head1 AUTHOR  =head1 AUTHOR
716    
717  Dobrica Pavlinusic <dpavlin@rot13.org>  Dobrica Pavlinusic <dpavlin@rot13.org>

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.26