2 # Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use lib '@amperldir@';
24 use Amanda::Device qw( :constants );
25 use Amanda::Config qw( :getconf :init );
26 use Amanda::Debug qw( :logging );
27 use Amanda::Util qw( :constants );
29 # try to open the device and read its label, returning the device_read_label
30 # result (one or more of ReadLabelStatusFlags)
32 my ($device_name) = @_;
34 if ( !$device_name ) {
35 die("No device name specified.\n");
40 my $device = Amanda::Device->new($device_name);
42 die("Error creating $device_name");
45 if ($device->status() == $DEVICE_STATUS_SUCCESS) {
46 $result = $device->read_label();
48 $result = $device->status();
51 print_result( $result, $device->error() );
55 # print the results, one flag per line
57 my ($flags, $errmsg) = @_;
59 if ($flags != $DEVICE_STATUS_SUCCESS) {
60 print "MESSAGE $errmsg\n";
62 print join( "\n", DeviceStatusFlags_to_strings($flags) ), "\n";
67 Usage: amdevcheck <config> [ <device name> ]
72 ## Application initialization
74 Amanda::Util::setup_application("amdevcheck", "server", $CONTEXT_SCRIPTUTIL);
76 my $config_overwrites = new_config_overwrites($#ARGV+1);
78 Getopt::Long::Configure(qw(bundling));
80 'help|usage|?' => \&usage,
81 'o=s' => sub { add_config_overwrite_opt($config_overwrites, $_[1]); },
84 usage() if ( @ARGV < 1 || @ARGV > 2 );
85 my $config_name = $ARGV[0];
87 config_init($CONFIG_INIT_EXPLICIT_NAME, $config_name);
88 apply_config_overwrites($config_overwrites);
89 my ($cfgerr_level, @cfgerr_errors) = config_errors();
90 if ($cfgerr_level >= $CFGERR_WARNINGS) {
91 config_print_errors();
92 if ($cfgerr_level >= $CFGERR_ERRORS) {
93 die("errors processing config file");
97 Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
103 $device_name = $ARGV[1];
105 $device_name = getconf($CNF_TAPEDEV);
108 try_read_label($device_name);