ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/scripts/fput
Revision: 136
Committed: Tue Dec 13 16:18:24 2011 UTC (7 years, 9 months ago) by gpertea
File size: 1417 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=q/
9 Usage
10 fput [<scp_opts>] remote_dir local_files...
11 /;
12
13 die "$usage\n" unless @ARGV>=2;
14 my $athome=check_server('192.168.2.4', 22);
15 my $host='gwork';
16 my $port='';
17 if ($athome) {
18 $port='-P 5022';
19 $host = '192.168.2.4';
20 }
21 my $opts;
22 while ($ARGV[0]=~m/^\-[BCpqrv\d]+/) {
23 $opts.=shift(@ARGV).' ';
24 }
25
26 my $rpath=shift(@ARGV);
27 $rpath=$ENV{PWD} if $rpath eq '.';
28 #$rpath=~s/home\/gpertea\//nfshomes\/gpertea\//;
29 my $cmd='scp '.$opts.' -pr '.$port." '".join("' '",@ARGV)."' $host\:".$rpath;
30 system($cmd);
31
32 sub check_server {
33 my $host=$_[0] || "snowy.gotdns.org";
34 my $port=$_[1] || 22;
35 #print STDERR "Connecting to $host..\n";
36 my $rlen :shared; #length of received data
37
38 my $t = async {
39 my $sock = new IO::Socket::INET (
40 PeerAddr => $host,
41 PeerPort => $port,
42 Proto => 'tcp',
43 Blocking => 0
44 );
45 return 0 if !$sock;
46 sleep(0.2);
47 #select(undef,undef,undef, 0.150); #150ms pause
48 #this works on all platforms
49 my $buf;
50 my $servdata='';
51 while (sysread($sock, $buf, 1024)) {
52 $servdata .= $buf;
53 last;
54 }
55 $rlen=length($servdata);
56 };
57 my $timeout=0.6;
58 until ($rlen || $timeout <= 0) {
59 $timeout -= 0.1; #poll interval
60 sleep(0.1);
61 }
62 $t->detach();
63 return ($rlen>0) ? 1 : 0;
64 }

Properties

Name Value
svn:executable *