| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# ecaccess-file-size: Show the Size of an ECaccess File |
| 4 |
# |
| 5 |
# [email protected] - 2010-10-15 |
| 6 |
|
| 7 |
use ECMWF::ECaccess; |
| 8 |
use Getopt::Long; |
| 9 |
use Pod::Usage; |
| 10 |
use Number::Bytes::Human qw(format_bytes); |
| 11 |
|
| 12 |
my %opt = ( human => 0, version => 0, help => 0, manual => 0, retry => 0, debug => 0 ); |
| 13 |
|
| 14 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions( |
| 15 |
\%opt, |
| 16 |
qw( |
| 17 |
human |
| 18 |
version |
| 19 |
help|? |
| 20 |
manual |
| 21 |
retry=i |
| 22 |
debug |
| 23 |
) |
| 24 |
); |
| 25 |
|
| 26 |
# Display version if requested |
| 27 |
die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} ); |
| 28 |
|
| 29 |
my $ecaccessFile = $ARGV[0]; |
| 30 |
|
| 31 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} ); |
| 32 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} ); |
| 33 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No file specified!\n" ) if not($ecaccessFile); |
| 34 |
|
| 35 |
# Create the ECaccess Controler |
| 36 |
my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug}); |
| 37 |
|
| 38 |
# Get the Token (using the Certificate in $HOME) |
| 39 |
my $token = $ecaccess->getToken(); |
| 40 |
|
| 41 |
# Get the Control Channel |
| 42 |
my $controlChannel = $ecaccess->getControlChannel(); |
| 43 |
|
| 44 |
# Get the modtime |
| 45 |
my $size = $controlChannel->getFileSize( $token, $ecaccessFile )->result; |
| 46 |
|
| 47 |
# Display the result |
| 48 |
if ( $opt{human} ) { |
| 49 |
print format_bytes($size) . "\n"; |
| 50 |
} |
| 51 |
else { |
| 52 |
print $size. "\n"; |
| 53 |
} |
| 54 |
|
| 55 |
# Logout |
| 56 |
END { |
| 57 |
$ecaccess->releaseToken($token) if ($token); |
| 58 |
} |
| 59 |
|
| 60 |
__END__ |
| 61 |
|
| 62 |
=head1 NAME |
| 63 |
|
| 64 |
ecaccess-file-size - Show the Size of an ECaccess File |
| 65 |
|
| 66 |
=head1 SYNOPSIS |
| 67 |
|
| 68 |
B<ecaccess-file-size -version|-help|-manual> |
| 69 |
|
| 70 |
B<ecaccess-file-size [-debug] [-human]> I<ecaccess-file> |
| 71 |
|
| 72 |
=head1 DESCRIPTION |
| 73 |
|
| 74 |
Allow showing the size of I<ecaccess-file> (-1 for a directory). |
| 75 |
|
| 76 |
The I<ecaccess-file> is in the form [domain:][/user-id/]path. Please read the "Shell commands -> File Management" |
| 77 |
section of the "ecaccess" guide for more information on the ECaccess File System. |
| 78 |
|
| 79 |
=head1 ARGUMENTS |
| 80 |
|
| 81 |
=over 8 |
| 82 |
|
| 83 |
=item I<ecaccess-file> |
| 84 |
|
| 85 |
Then name of the ECaccess File to get the size. |
| 86 |
|
| 87 |
=back |
| 88 |
|
| 89 |
=head1 OPTIONS |
| 90 |
|
| 91 |
=over 8 |
| 92 |
|
| 93 |
=item B<-human> |
| 94 |
|
| 95 |
Print size in human readable format (e.g. 234M). |
| 96 |
|
| 97 |
=item B<-version> |
| 98 |
|
| 99 |
Display version number and exits. |
| 100 |
|
| 101 |
=item B<-help> |
| 102 |
|
| 103 |
Print a brief help message and exits. |
| 104 |
|
| 105 |
=item B<-manual> |
| 106 |
|
| 107 |
Prints the manual page and exits. |
| 108 |
|
| 109 |
=item B<-retry> I<count> |
| 110 |
|
| 111 |
Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the |
| 112 |
initial SSL connection initiated by the command to the ECMWF server. It does not |
| 113 |
apply to all the subsequent requests made afteward as it is mainly targeting errors |
| 114 |
that can happen from time to time during the SSL handshake. Default is no retry. |
| 115 |
|
| 116 |
=item B<-debug> |
| 117 |
|
| 118 |
Display the SOAP and SSL messages exchanged. |
| 119 |
|
| 120 |
=back |
| 121 |
|
| 122 |
=head1 EXAMPLES |
| 123 |
|
| 124 |
B<ecaccess-file-size> I<bin/a.out> |
| 125 |
|
| 126 |
Display the Size of the I<a.out> File in the $HOME/bin directory of the authenticated user. |
| 127 |
|
| 128 |
=head1 SEE ALSO |
| 129 |
|
| 130 |
B<ecaccess-file-delete>, B<ecaccess-file-get>, B<ecaccess-file-mget>, B<ecaccess-file-modtime>, B<ecaccess-file-mput>, |
| 131 |
B<ecaccess-file-rmdir>, B<ecaccess-file-copy>, B<ecaccess-file-dir>, B<ecaccess-file-mdelete>, B<ecaccess-file-mkdir>, |
| 132 |
B<ecaccess-file-move>, B<ecaccess-file-put>, B<ecaccess-file-chmod> and B<ecaccess>. |
| 133 |
|
| 134 |
=cut |