Last active
March 18, 2024 14:12
-
-
Save Lathanao/6c3fbf630ee2234226542436c4e28c40 to your computer and use it in GitHub Desktop.
Performance tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -xe | |
# Performance tracker (MIT License) | |
# By Lathanao (last update: 24/11/2023) | |
# | |
# Script work well when that has been set: | |
# $ echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/no-more-password" | |
# $ sudo ln -s /dir/of/Scripts/* /etc/cron.daily/ | |
LOG_DIR=/var/log/usercron | |
LOG_FILE=/var/log/usercron/cpu-tracker.log | |
if [[ ! -d "$LOG_DIR" ]];then | |
sudo mkdir -p $LOG_DIR | |
sudo chmod -R 0700 $LOG_DIR | |
sudo chown -R $USER:$USER $LOG_DIR | |
fi | |
if [[ ! -f "$LOG_FILE" ]];then | |
sudo touch $LOG_FILE | |
sudo chmod 0700 $LOG_FILE | |
sudo chown $USER:$USER $LOG_FILE | |
fi | |
UPTIME_IN=$(awk '{print $1}' /proc/uptime) | |
RES=`time echo "scale=5000; 4*a(1)" | bc -l` | |
UPTIME_OUT=$(awk '{print $1}' /proc/uptime) | |
TIME_EXE=$(echo "scale=2;$UPTIME_OUT-$UPTIME_IN" | bc) | |
DATE=$(date +"%Y-%m-%d %T") | |
echo $DATE $(whoami) $TIME_EXE >> $LOG_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment