Browse Source

Basic logging

Added logging functionality. nmcli really doesn't output anything when
you configure stuff. Probably because it's a cli version of a GUI based
app.

See changes for more information. Log file name is nmcli-basic.log
master
Brandon Nolet 1 year ago
parent
commit
5972c2ac12
1 changed files with 16 additions and 6 deletions
  1. 16
    6
      nmcli-basic.sh

+ 16
- 6
nmcli-basic.sh View File

@@ -18,7 +18,10 @@ function usage() {
"
}

#Global Vars
NMCLI_BIN=$(which nmcli)
TIMESTAMP=$(date +%H:%M:%S)
LOGFILE=nmcli-basic.log

# `setstatic` works as a state machine, running through
# each case statement in order of operation. This is Done
@@ -66,9 +69,13 @@ case $1 in #case to enable returnability
#Setting Static IP info
echo "Configuring..."
nmcli con mod ${IntID} ipv4.addresses ${IPAdd}/${PrefLen}
echo "${TIMESTAMP}: IPv4 address of ${IntID} set to ${IPAdd}/${PrefLen}." >> ${LOGFILE}
nmcli con mod ${IntID} ipv4.gateway ${GatewayIP}
nmcli con mod ${IntID} ipv4.dns "${DNSAdd}" #Surrounded in quotes for multiple DNS servers
echo "${TIMESTAMP}: ${IntID} default gateway set to ${GatewayIP}." >> ${LOGFILE}
nmcli con mod ${IntID} ipv4.dns "${DNSAdd}" #Surrounded in quotes for multiple DNS servers
echo "${TIMESTAMP}: ${IntID}'s DNS servers are now ${DNSAdd}." >> ${LOGFILE}
nmcli con mod ${IntID} ipv4.method manual
echo "${TIMESTAMP}: ${IntID}'s resulting addressing method is \"Static\"" >> ${LOGFILE}

reloadint
;;
@@ -90,14 +97,14 @@ function reloadint() {
#to apply the changes

echo "Applying changes..."
nmcli con down ${IntID} > /dev/null
nmcli con up ${IntID} > /dev/null
nmcli con down ${IntID} | sed "s/^/${TIMESTAMP}: /" >> ${LOGFILE}
nmcli con up ${IntID} | sed "s/^/${TIMESTAMP}: /" >> ${LOGFILE}
echo "Done!"
}

function conshow() {

${NMCLI_BIN} con show
${NMCLI_BIN} con show | tee --append ${LOGFILE}

echo
read -p "Which interface to configure? " IntID
@@ -127,7 +134,7 @@ function conshow() {

}

# `valid IP` is meant to check for proper IP address formatting
# `validip` is meant to check for proper IP address formatting
# `validip` accepts 3 arguments. The first is the state (an integer)
# to return to on incorrect format detection. The second is the state
# to move to on success
@@ -170,7 +177,8 @@ function getchoice() {
;;
*)
echo
echo "Sorry, that's not a valid option"
echo "Sorry, that's not a valid option."
echo "Try ./nmcli-basic usage for more information."
echo
sleep 1
getchoice
@@ -178,7 +186,9 @@ function getchoice() {
esac
}

echo "Start of script run: `date +%H:%M:%S`" >> nmcli-basic.log
getchoice $1
echo "End of script run: `date +%H:%M:%S`" >> nmcli-basic.log

exit 0


Loading…
Cancel
Save