Added check for state of VM/CT to avoid errors
This commit is contained in:
@@ -57,7 +57,7 @@ while true; do
|
|||||||
UpdatePKG=true
|
UpdatePKG=true
|
||||||
UpdateAPP=true
|
UpdateAPP=true
|
||||||
break;;
|
break;;
|
||||||
* ) echo "Please answer with (A)ll, (C)T`s or (V)M`s.";;
|
* ) echo "Please answer with (P)ackages, (A)pplications or (B)oth.";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -66,6 +66,8 @@ if $UpdateCT; then
|
|||||||
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
|
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
|
||||||
#Skip CT if in ExcludeList
|
#Skip CT if in ExcludeList
|
||||||
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi
|
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi
|
||||||
|
# Skip CT if not running
|
||||||
|
if ! $(CT-State $CTID); then echo "Notice: $CTID not running"; continue; fi
|
||||||
#DEBUG echo "Task for $CTID"
|
#DEBUG echo "Task for $CTID"
|
||||||
if $UpdatePKG; then
|
if $UpdatePKG; then
|
||||||
CT-UpdatePackages $CTID | tee "$LogDir"/"$CTID"_Pkgs.log
|
CT-UpdatePackages $CTID | tee "$LogDir"/"$CTID"_Pkgs.log
|
||||||
@@ -79,8 +81,10 @@ fi
|
|||||||
#VM Updates
|
#VM Updates
|
||||||
if $UpdateVM; then
|
if $UpdateVM; then
|
||||||
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
|
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
|
||||||
#Skip CT if in ExcludeList
|
#Skip VM if in ExcludeList
|
||||||
if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi
|
if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi
|
||||||
|
# Skip VM if not running
|
||||||
|
if ! $(VM-State $VMID); then echo "Notice: $VMID not running"; continue; fi
|
||||||
#DEBUG echo "Task for $VMID"
|
#DEBUG echo "Task for $VMID"
|
||||||
if $UpdatePKG; then
|
if $UpdatePKG; then
|
||||||
VM-UpdatePackages $VMID | tee "$LogDir"/"$VMID"_Pkgs.log
|
VM-UpdatePackages $VMID | tee "$LogDir"/"$VMID"_Pkgs.log
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ if ! $IdExists; then echo "This ID does not exist"; exit; fi
|
|||||||
if [[ $VMS =~ $ID ]]; then TYPE=VM; fi
|
if [[ $VMS =~ $ID ]]; then TYPE=VM; fi
|
||||||
if [[ $CTS =~ $ID ]]; then TYPE=CT; fi
|
if [[ $CTS =~ $ID ]]; then TYPE=CT; fi
|
||||||
|
|
||||||
|
check#Check if VM/CT is running
|
||||||
|
if ! $($TYPE-State $ID); then echo "This ID is not runnig"; exit; fi
|
||||||
|
|
||||||
#Ask what should be updated
|
#Ask what should be updated
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Wich software should be updated (P)ackages, (A)pplications or (B)oth? " sofq
|
read -p "Wich software should be updated (P)ackages, (A)pplications or (B)oth? " sofq
|
||||||
@@ -52,6 +55,6 @@ while true; do
|
|||||||
$TYPE-UpdatePackages $ID
|
$TYPE-UpdatePackages $ID
|
||||||
$TYPE-UpdateApplicatons $ID
|
$TYPE-UpdateApplicatons $ID
|
||||||
break;;
|
break;;
|
||||||
* ) echo "Please answer with (A)ll, (C)T`s or (V)M`s.";;
|
* ) echo "Please answer with (P)ackages, (A)pplications or (B)oth.";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|||||||
28
functions.sh
28
functions.sh
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
##########################
|
##########################
|
||||||
# ProxMox update tools #
|
# ProxMox update tools #
|
||||||
# FUNCTIONS #
|
# FUNCTIONS #
|
||||||
# @author: Bram Prieshof #
|
# @author: Bram Prieshof #
|
||||||
##########################
|
##########################
|
||||||
|
|
||||||
@@ -92,3 +92,29 @@ VM-UpdateApplicatons () {
|
|||||||
#exit 102
|
#exit 102
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Get state of CT as exitcode (0 when running 1 when stoped and 2 if CT is existend or other error occurs)
|
||||||
|
CT-State () {
|
||||||
|
if [ -z ${CTID+x} ]; then local CTID=$1;fi
|
||||||
|
case "$(pct status $CTID 2>&1)" in
|
||||||
|
*running* )
|
||||||
|
return 0;;
|
||||||
|
*stopped* )
|
||||||
|
return 1;;
|
||||||
|
* )
|
||||||
|
return 2;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
#Get state of VM as exitcode (0 when running 1 when stoped and 2 if VM is existend or other error occurs)
|
||||||
|
VM-State (){
|
||||||
|
if [ -z ${VMID+x} ]; then local VMID=$1;fi
|
||||||
|
case "$(qm status $VMID 2>&1)" in
|
||||||
|
*running* )
|
||||||
|
return 0;;
|
||||||
|
*stopped* )
|
||||||
|
return 1;;
|
||||||
|
* )
|
||||||
|
return 2;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user