File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,7 +31,6 @@ LOCUST_FILE="$EXTRACT_DIR/SystemGuard-*/src/scripts/locustfile.py"
3131HOST_URL=" http://localhost:5050"
3232INSTALLER_SCRIPT=' setup.sh'
3333
34- echo " User: $( whoami) "
3534# Create necessary directories
3635mkdir -p " $LOG_DIR "
3736mkdir -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}
Original file line number Diff line number Diff line change 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
410add_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
You can’t perform that action at this time.
0 commit comments