aus. Das folgende Shell-Skript fragt den Benutzer nach Stunde und Minute. Wenn Sie diese beiden Eingaben eingeben, wird die Bildgebung geplant. Wenn ich versuche, dieses Skript als root wie folgt auszuführen: bash -x /run/opt/corp/cmtg/2.0.0/sesm/admin/scripts/configure_gwcautoimaging 13 56
. Ich bekomme folgende Fehlermeldung: typset:'13': not a valid identifier and typset:'56': not a valid identifier.
Führen Sie ein Shell-Skript mit dem Eingabeparameter
Meine Frage ist, wie kann ich dieses Skript mit seinem Parameter in einer Zeile ausführen. Ich habe auch versucht ./run/opt/corp/cmtg/2.0.0/sesm/admin/scripts/configure_gwcautoimaging << "16 16"
und sh /run/opt/corp/cmtg/2.0.0/sesm/admin/scripts/configure_gwcautoimaging 16 50
, aber sie haben nicht funktioniert, ich habe den gleichen Fehler.
#!/bin/bash
DEBUG="";
#DEBUG="set -x";
eval $DEBUG;
typeset inputHour=2;
typeset inputMinute=0;
typeset crontabsFile="/etc/crontab";
typeset tmp_crontabsFile="/tmp/crontab.tmp";
typeset imagingsh=$BIN_DIR/autoimaging.sh;
function validateNumber
{
eval $DEBUG;
typeset -i vInput=$1;
if [[ $? != 0 ]]
then
return 1;
fi
typeset -i vBase=$2;
if [[ $? != 0 ]]
then
return 1;
fi
if ((vInput < 0 || vInput >= vBase))
then
return 1;
fi
return 0;
}
function updatecrontabs
{
eval $DEBUG;
typeset hour=$1;
typeset minute=$2;
#remove any entries that already have the autoimaging.sh
/bin/grep -v "${imagingsh}" $crontabsFile > ${tmp_crontabsFile};
cat <<- EOF >> $tmp_crontabsFile
$inputMinute $inputHour * * * $imagingsh
EOF
crontab ${tmp_crontabsFile}
if [[ $? != 0 ]]
then
return 1;
fi
cp ${tmp_crontabsFile} ${crontabsFile};
}
# If this script is invoked with two parameters, parse the two parameters as Hour and Minute
# Otherwise, get input from user.
if [[ $# != 2 ]]
then
echo " Configure Auto Imaging ";
while (true)
do
echo -n "Please input the hour when the Auto Imaging is to be executed: ";
read inputHour
if [[ -n $inputHour ]]
then
validateNumber $inputHour 24;
if [[ $? == 0 ]]
then
break;
else
echo "You must input the number between 0 and 24";
echo " ";
fi
else
echo "You must input the number between 0 and 24";
echo " ";
fi
done
while (true)
do
echo -n "Please input the minute when the Auto Imaging is to be executed: ";
read inputMinute
if [[ -n $inputMinute ]]
then
validateNumber $inputMinute 60;
if [[ $? == 0 ]]
then
break;
else
echo "You must input the number between 0 and 60";
echo " ";
fi
else
echo "You must input the number between 0 and 60";
echo " ";
fi
done
else
inputHour=$1;
inputMinute=$2;
typeset vResult=validateNumber $inputHour 24;
if [[ $vResult != 0 ]]
then
echo "The number for hour must be between 0 and 24";
exit 1;
fi
vResult= validateNumber $inputMinute 60;
if [[ $vResult != 0 ]]
then
echo "The number for minute must be between 0 and 60";
exit 1;
fi
fi
# Begin update the entry: auto imaging in crontabs
updatecrontabs $inputHour $inputMinute;
if [[ $? == 0 ]]
then
echo "update crontabs successfully! The auto imaging will be executed at: " $inputHour ":" $inputMinute;
echo " ";
else
echo "Errors happen during update crontabs";
echo " "
exit 1;
fi
rm ${tmp_crontabsFile} > /dev/null;
exit 0;
lernen Shell Debug/Trace-Funktionen zu verwenden, das heißt 'set -vx; PS4 = '$ {LINENO} #>' 'Um auszuschalten, benutze' set + vx; PS4 deaktivieren '. Viel Glück. – shellter