#!/bin/bash # shellscript to execute a list of shell commands # with the chance to interfere with own commands VERSION="0.4 Wed Mar 3 18:27:00 CET 2010" # Copyright (C) 2010 Ronald Woelfel # # 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 2 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, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ----------------------------------------------------------------- # comment out, if there are problems with ansi-code sequences esc=`echo -en "\033"` red="$esc[1;31m" green="$esc[1;32m" blue="$esc[1;34m" norm="$esc[m" # Shellcommands stored in a array cmd # this is a example to compile nagios, substitute with your # own shell commands cmd=( '# write down your commands here' 'tar zxyf xyz.tgz' ) # dont change anything below, unless you know what your are doing number=${#cmd[*]} zl=0 # execute shell commands step by step while [ $zl -lt $number ] do echo -n "${blue}Next: ${norm}" firstchar=${cmd[$zl]:0:1} # If the next command starts wie a comment (#) then # use colour green if test $firstchar = "#" then # do a little sleep if "#" is the only character in current line test ${#cmd[$zl]} -eq 1 && { echo ""; cmd[$zl]="############################################################"; } echo "$green ${cmd[$zl]} ${norm}" zl=`expr $zl + 1` continue else echo "$red ${cmd[$zl]} ${norm}" fi echo -n "${blue}Execute? (y)/n: ${norm} " read key test -z $key && key="y" if [ $key == "n" ] then echo "Give alternativ command or just ENTER to do nothing" read usercommand eval $usercommand else eval ${cmd[$zl]} fi zl=`expr $zl + 1` done