Skip to content

Commit c027513

Browse files
chore: Refactor setup.sh and cronjob.sh scripts
1 parent d10b299 commit c027513

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

setup.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ LOCUST_FILE="$EXTRACT_DIR/SystemGuard-*/src/scripts/locustfile.py"
3131
HOST_URL="http://localhost:5050"
3232
INSTALLER_SCRIPT='setup.sh'
3333

34-
echo "User: $(whoami)"
3534
# Create necessary directories
3635
mkdir -p "$LOG_DIR"
3736
mkdir -p "$BACKUP_DIR"
@@ -190,7 +189,6 @@ install() {
190189
./cronjob.sh
191190

192191
# Install the executable
193-
log "Installing executable to /usr/local/bin/systemguard-installer..."
194192
install_executable
195193
log "SystemGuard version $VERSION installed successfully!"
196194
}

src/scripts/cronjob.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22

3+
# Function to log messages with timestamp
4+
log_with_timestamp() {
5+
local message="$1"
6+
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message"
7+
}
8+
39
# Function to add a cron job with error handling
410
add_cron_job() {
511
# Define log directory and cron job command
@@ -10,24 +16,24 @@ add_cron_job() {
1016
# Create log directory with error handling
1117
mkdir -p "$log_dir"
1218
if [ $? -ne 0 ]; then
13-
echo "Error: Failed to create log directory: $log_dir"
19+
log_with_timestamp "Error: Failed to create log directory: $log_dir"
1420
exit 1
1521
fi
1622

1723
# Verify user retrieval
1824
if [ -z "$username" ]; then
19-
echo "Error: Unable to retrieve current username."
25+
log_with_timestamp "Error: Unable to retrieve current username."
2026
exit 1
2127
fi
2228

2329
# Add cron job to crontab with error handling
2430
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
2531
if [ $? -ne 0 ]; then
26-
echo "Error: Failed to add the cron job to the crontab."
32+
log_with_timestamp "Error: Failed to add the cron job to the crontab."
2733
exit 1
2834
fi
2935

30-
echo "Cron job added: $cron_job"
36+
log_with_timestamp "Cron job added: $cron_job"
3137
}
3238

3339
# Call the function to add the cron job

0 commit comments

Comments
 (0)