diff --git a/blink/blink b/blink/blink new file mode 100755 index 0000000..e1da3a0 --- /dev/null +++ b/blink/blink @@ -0,0 +1,197 @@ +#!/usr/bin/perl + +=head1 NAME + +blink - blink disks in a disk enclosure + + +=head1 SYNOPSIS + +B [--on|--off|--toggle] [I|--all|--all-detected|--all-slots] + +B I I + + +=head1 DESCRIPTION + +B blinks a device in an external harddisk enclosure. If some +devices are already blinking, B will turn off blinking of all +devices. + +If no I is given the blinking be will toggled. + +If no I is given all detected disks in external enclosures will +be used. + + +=head1 OPTIONS + +=over 9 + +=item I + +What action to do. One of B<-n>, B<--on>, B<-f>, B<--off>, B<-t>, +B<--toggle>. Default is B<--toggle>. + + +=item I + +What slots to perform the action on. One of B<-d>, B<--all>, +B<--all-detected>, B<-s>, B<--all-slots>, I. Default is +B<--all-detected>. + + +=item I + +The disk device to blink. Either as I or as I. + + +=item B<--all-detected> + +=item B<--all> + +=item B<-d> + +Select all the detected devices. + + +=item B<--all-slots> + +=item B<-s> + +Select all slots in the enclosures. + + +=item B<--on> + +=item B<-n> + +Turn the blink on. + + +=item B<--off> + +=item B<-f> + +Turn the blink off. + + +=item B<--toggle> + +=item B<-t> + +Toggle the blink. + + +=back + +=head1 EXAMPLE: Blink harddisk /dev/sdf + +To blink /dev/sdf + +B + + +=head1 EXIT STATUS + +Always returns true. + + +=head1 REPORTING BUGS + +Contact Ole Tange . + + +=head1 AUTHOR + +Copyright (C) 2012 Ole Tange . + + +=head1 LICENSE + +Copyright (C) 2012 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +at your option any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + +=head1 DEPENDENCIES + +B uses Perl and GNU Parallel. + + +=head1 SEE ALSO + +B(1), B(1). + +=cut + +use Getopt::Long; + +GetOptions( + "n|on" => \$::opt_on, + "f|off" => \$::opt_off, + "t|toggle" => \$::opt_toggle, + "d|all|all-detected|alldetected" => \$::opt_alldetected, + "s|all-slots|allslots" => \$::opt_allslots, + ); + +if(@ARGV) { + for(@ARGV) { + s:/dev/::g; + } +} + +if($::opt_alldetected) { + $locate = "/sys/class/enclosure/*/*/device/block/sd*/../../enclosure*/locate"; +} elsif($::opt_allslots) { + $locate = "/sys/class/enclosure/*/*/device/enclosure*/locate"; +} else { + if($#ARGV == 0) { + $dev = shift; + } else { + local($"=","); + $dev = @ARGV ? "{@ARGV}" : "*"; + } + $locate = "/sys/class/enclosure/*/*/device/block/$dev/../../enclosure*/locate"; +} + +if($::opt_on) { + on($locate); +} elsif($::opt_off) { + off($locate); +} else { + toggle($locate); +} + + +sub on { + my $locate = shift; + print("parallel echo 1 \\> ::: $locate\n"); + system("parallel echo 1 \\> ::: $locate\n"); +} + + +sub off { + my $locate = shift; + print("parallel echo 0 \\> ::: $locate\n"); + system("parallel echo 0 \\> ::: $locate\n"); +} + + +sub toggle { + my $locate = shift; + # If the file 'locate' contains 1 it should be put to 0. + print('parallel grep -q 1 {} \; echo \$? \\> {} :::'." $locate\n"); + system('parallel grep -q 1 {} \; echo \$? \\> {} :::'." $locate\n"); +} diff --git a/em/em b/em/em index 30d7ce1..e99432c 100755 --- a/em/em +++ b/em/em @@ -1,3 +1,5 @@ #!/bin/bash -exec emacs -nw "$@" +EMACS=`which emacs || which xemacs` + +exec $EMACS -nw "$@"