Code:
START=$SECONDS
The code is run after the desktop appears and after the WiFi connection message appears as the scripts mostly install stuff. I guess the computer might adjust time based on the internet time. I usually open the file manager to look at things then open terminal. Perhaps I could wait longer before using the script if the OS is adjusting the time based on the Internet.I suspect you are running the script soon after boot
The problem with waiting is simple. I ran an install-all script which runs child scripts. About ten minutes in, there was a faulty SECONDS.
Here is the start of a revised script using your suggestions. I also added to the end. I do not know how to calculate the difference using the etimes variation. I will run this several times to see if there is a difference.
Code:
#!/bin/bash# Upgrade packages. Apply all updates for packages.UPGRADESTART=$SECONDSUPGRADEACTIVITY="install-upgrade"if [ -z ${ALOG+x} ]; then DATETIME=$(date +%F_%H-%M-%S) ALOG="$DATETIME $UPGRADEACTIVITY".log echo "Created log: $ALOG"; else echo "Use existing log: $ALOG"; fiecho "$UPGRADEACTIVITY start." | tee -a "$ALOG"echo "SECONDS: $SECONDS." | tee -a "$ALOG"echo "etimes: $(ps --no-headers -o etimes $$)" | tee -a "$ALOG"
Code:
echo "SECONDS: $SECONDS." | tee -a "$ALOG"echo "etimes: $(ps --no-headers -o etimes $$)" | tee -a "$ALOG"echo "$UPGRADEACTIVITY end. Used $(( SECONDS - UPGRADESTART )) seconds." | tee -a "$ALOG"
Statistics: Posted by peterlite — Sun Jan 05, 2025 9:51 pm