Skip to content

Commit d10b299

Browse files
chore: Update SystemGuard app setup script and dependencies in crontab
1 parent daadb3f commit d10b299

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# SystemGuard
1+
# SystemGuard 💂
22

33
System Guard is a Flask app designed to monitor server stats such as CPU, Memory, Disk, and Network. It also provides real-time monitoring capabilities which can be useful for system administrators, developers, and DevOps engineers to keep track of their server's performance and troubleshoot issues. The app uses the `psutil` library to retrieve system stats and the `speedtest-cli` library to perform a network speed test.
44

5-
## Installation
5+
## Installation 🛠️
66

77
```bash
88
wget https://raw.githubusercontent.com/codeperfectplus/SystemGuard/main/setup.sh
@@ -40,7 +40,7 @@ It will install the SystemGuard app and its dependencies in the crontab and it w
4040

4141
- Anaconda3/Miniconda3
4242

43-
## Features
43+
## Features 🚀
4444

4545
- Monitor server stats like CPU, Memory, Disk, and Network.
4646
- Check the network speed of the server using a speed test.
@@ -52,7 +52,7 @@ It will install the SystemGuard app and its dependencies in the crontab and it w
5252
- Easy download and installation using a bash script.
5353

5454

55-
## Product Screenshots
55+
## Product Screenshots 📸
5656

5757
### HomePage
5858

setup.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ get_user_home() {
2222
# Set paths relative to the correct user's home directory
2323
USER_HOME=$(get_user_home)
2424
DOWNLOAD_DIR="/tmp"
25-
EXTRACT_DIR="$USER_HOME/.systemguard"
25+
EXTRACT_DIR="$USER_HOME/.systemguard/"
2626
LOG_DIR="$HOME/logs"
2727
LOG_FILE="$LOG_DIR/systemguard-installer.log"
2828
BACKUP_DIR="$USER_HOME/.systemguard_backup"
@@ -99,7 +99,6 @@ install_executable() {
9999
# CURRENT_SCRIPT=$(realpath "$0")
100100
cd $EXTRACT_DIR/SystemGuard-*/
101101
CURRENT_SCRIPT=$(pwd)/$INSTALLER_SCRIPT
102-
echo "Current script: $CURRENT_SCRIPT"
103102
# Verify that the script exists before attempting to copy
104103
if [ -f "$CURRENT_SCRIPT" ]; then
105104
log "Installing executable to /usr/local/bin/systemguard-installer..."
@@ -139,12 +138,12 @@ install() {
139138
log "Installing SystemGuard version $VERSION..."
140139

141140
# Download the SystemGuard zip file
142-
wget -q $ZIP_URL -O $DOWNLOAD_DIR/systemguard.zip
143-
if [ $? -ne 0 ]; then
141+
log "Downloading SystemGuard version $VERSION from $ZIP_URL..."
142+
if ! wget -q "$ZIP_URL" -O "$DOWNLOAD_DIR/systemguard.zip"; then
144143
log "Error: Failed to download SystemGuard version $VERSION. Please check the version number and try again."
145144
exit 1
146145
fi
147-
log "Download completed."
146+
log "Download completed successfully."
148147

149148
# Backup existing configurations
150149
backup_configs

src/scripts/cronjob.sh

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
#!/bin/bash
22

3-
# Define the cron job command
4-
username=$(whoami)
5-
log_dir="/home/$username/logs"
6-
mkdir -p "$log_dir"
7-
CRON_JOB="* * * * * /bin/bash $(pwd)/dashboard.sh >> $log_dir/systemguard_cron.log 2>&1"
8-
9-
echo "Total cron jobs before: $(crontab -l | grep -v '^#' | wc -l)"
10-
11-
# Add the cron job to the crontab
12-
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
13-
14-
echo "Cron job added: $CRON_JOB"
15-
16-
# show all cron jobs ignoring comments and empty lines
17-
18-
echo "Total cron jobs after: $(crontab -l | grep -v '^#' | wc -l)"
19-
20-
21-
3+
# Function to add a cron job with error handling
4+
add_cron_job() {
5+
# Define log directory and cron job command
6+
local username=$(whoami)
7+
local log_dir="/home/$username/logs"
8+
local cron_job="* * * * * /bin/bash $(pwd)/dashboard.sh >> $log_dir/systemguard_cron.log 2>&1"
9+
10+
# Create log directory with error handling
11+
mkdir -p "$log_dir"
12+
if [ $? -ne 0 ]; then
13+
echo "Error: Failed to create log directory: $log_dir"
14+
exit 1
15+
fi
16+
17+
# Verify user retrieval
18+
if [ -z "$username" ]; then
19+
echo "Error: Unable to retrieve current username."
20+
exit 1
21+
fi
22+
23+
# Add cron job to crontab with error handling
24+
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
25+
if [ $? -ne 0 ]; then
26+
echo "Error: Failed to add the cron job to the crontab."
27+
exit 1
28+
fi
29+
30+
echo "Cron job added: $cron_job"
31+
}
32+
33+
# Call the function to add the cron job
34+
add_cron_job

0 commit comments

Comments
 (0)