ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/scripts/fget
Revision: 136
Committed: Tue Dec 13 16:18:24 2011 UTC (7 years, 9 months ago) by gpertea
File size: 1361 byte(s)
Log Message:
added my mobile fput/fget scripts

Line File contents
1 #!/usr/bin/perl
2 use strict;
3 use threads;
4 use threads::shared;
5 use IO::Socket;
6 use Time::HiRes qw(sleep);
7
8 my $usage=qq/
9 Usage
10 fget [opts] remote_filepaths..
11 /;
12
13 die "$usage\n" unless @ARGV>=1;
14
15 my $athome=check_server('192.168.2.4', 22);
16 my $host='gwork';
17 $host = '-P 5022 192.168.2.4' if $athome;
18 my $opts;
19 while ($ARGV[0]=~m/^\-[BCpqrv\d]+/) {
20 $opts.=shift(@ARGV).' ';
21 }
22 my @files=@ARGV;
23 foreach (@files) {
24 $_=$ENV{PWD}.'/'.$_ unless m/^\//;
25 # s/home\/gpertea\//nfshomes\/gpertea\//;
26 my $cmd='scp '.$opts.' -pr '.$host.':'."'".$_."'".' .';
27 system($cmd);
28 }
29
30 sub check_server {
31 my $host=$_[0] || "snowy.gotdns.org";
32 my $port=$_[1] || 22;
33 #print STDERR "Connecting to $host..\n";
34 my $rlen :shared; #length of received data
35
36 my $t = async {
37 my $sock = new IO::Socket::INET (
38 PeerAddr => $host,
39 PeerPort => $port,
40 Proto => 'tcp',
41 Blocking => 0
42 );
43 return 0 if !$sock;
44 sleep(0.2);
45 #select(undef,undef,undef, 0.150); #150ms pause
46 #this works on all platforms
47 my $buf;
48 my $servdata='';
49 while (sysread($sock, $buf, 1024)) {
50 $servdata .= $buf;
51 last;
52 }
53 $rlen=length($servdata);
54 };
55 my $timeout=0.6;
56 until ($rlen || $timeout <= 0) {
57 $timeout -= 0.1; #poll interval
58 sleep(0.1);
59 }
60 $t->detach();
61 return ($rlen>0) ? 1 : 0;
62 }

Properties

Name Value
svn:executable *