I have a problem to adding a second case. I write this little script to login on pc and executing a command on them. But I'm having trouble defining a shortcut to the command. it should look like this, for example:
./script.sh 44 - login on this pc via ssh (this works)
./script.sh 44 r - reboot this pc via ssh (this don't works because i have a problems with defining a second case)
so for the test I wrote it:
LOG="$LOG""$AUT""$NMBR""$NR""$DOMAIN" "$Command"
$LOG
and define a variable
$Command
Command="sudo reboot"
but this command doesn't execute on pc what wrong i do ?
I put the entire script below.
DOMAIN="domain.domain.com"
PASS1="pass"
AUT="auth"
NMBR="001010"
LOG="sshpass -p$PASS1 ssh user@"
Command="sqlite3 /bin/ade/activity.sqlite 'Delete from state'"
if [[ $# == 0 ]]; then
echo "Invalid script call, give location or number as parameter:"
echo "2 / plau - NR 2 / Pn | I don't think it exists ?"
echo "44 / neun - NR 00101044 / Neundorf"
echo "45 / aks - NR 00101045 / Anton-Kraus-Straße"
echo "46 / chamiss - NR 00101046 / Chamissostraße"
echo "47 / prei - NR 00101047 / Preißelpöhl"
echo "48 / sud - NR 00101048 / Südvorstadt"
echo "49 / capitol - NR 00101049 / Capitol"
echo "50 / kgs - NR 00101050 / Dr.-Karl-Gelbke-Straße"
echo "51 / reusa - NR 00101051 / Reusa"
echo "52 / haus - NR 00101052 / Seehaus"
echo "53 / bus - NR 00101053 / Busbahnhof"
echo "54 / kn - NR 00101054 / Knielohstraße"
echo "55 / seume - NR 00101055 / Seumestraße"
echo "56 / neuels - NR 00101056 / Neue Elsterbrücke"
echo "57 / haupt - NR 00101057 / Hauptfriedhof"
echo "58 / tunnel2 - NR 00101058 / Tunnel II (Stadtgalerie)"
echo "59 / hlp - NR 00101059 / Hans-Löwel-Platz"
echo "60 / tunnel4 - NR 00101060 / Tunnel iV (PSB-Service)"
exit 1;
else
case in
"44") NR="0001"; LOGY="sshpass -p$PASS1 ssh mtvm@$AUT$NR$DOMAIN" ;;
"45") NR="45" ;;
"46") NR="46" ;;
"47") NR="47" ;;
"48") NR="48" ;;
"49") NR="49" ;;
"50") NR="50" ;;
"51") NR="51" ;;
"52") NR="52" ;;
"53") NR="53" ;;
"54") NR="54" ;;
"55") NR="55" ;;
"56") NR="56" ;;
"57") NR="57" ;;
"58") NR="58" ;;
"59") NR="59" ;;
"60") NR="60" ;;
"neun") NR="0001"; LOG2="sshpass -p$PASS1 ssh mtvm@$AUT$NR$DOMAIN" ;;
"aks") NR="45" ;;
"chamiss") NR="46" ;;
"prei") NR="47" ;;
"sud") NR="48" ;;
"capitol") NR="49" ;;
"kgs") NR="50" ;;
"reusa") NR="51" ;;
"haus") NR="52" ;;
"bus") NR="53" ;;
"kn") NR="54" ;;
"seume") NR="55" ;;
"neuels") NR="56" ;;
"haupt") NR="57" ;;
"tunnel2") NR="58" ;;
"hlp") NR="59" ;;
"tunnel4") NR="60" ;;
*) echo "Incorrect parameter"; exit 1 ;;
esac
echo "Login on $LOG$AUT$NMBR$NR$DOMAIN"
LOG="$LOG""$AUT""$NMBR""$NR""$DOMAIN" "$Command"
$LOG
LOG2="$LOG2"
$LOGY
fi
casestatement is missing a variable: it should becase $var in. Also, why are you adding a separate case for eachNRinstead of just sayingNR=$1?s