-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update SystemGuard app setup script and dependencies in crontab
- Loading branch information
1 parent
daadb3f
commit d10b299
Showing
3 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
#!/bin/bash | ||
|
||
# Define the cron job command | ||
username=$(whoami) | ||
log_dir="/home/$username/logs" | ||
mkdir -p "$log_dir" | ||
CRON_JOB="* * * * * /bin/bash $(pwd)/dashboard.sh >> $log_dir/systemguard_cron.log 2>&1" | ||
|
||
echo "Total cron jobs before: $(crontab -l | grep -v '^#' | wc -l)" | ||
|
||
# Add the cron job to the crontab | ||
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab - | ||
|
||
echo "Cron job added: $CRON_JOB" | ||
|
||
# show all cron jobs ignoring comments and empty lines | ||
|
||
echo "Total cron jobs after: $(crontab -l | grep -v '^#' | wc -l)" | ||
|
||
|
||
|
||
# Function to add a cron job with error handling | ||
add_cron_job() { | ||
# Define log directory and cron job command | ||
local username=$(whoami) | ||
local log_dir="/home/$username/logs" | ||
local cron_job="* * * * * /bin/bash $(pwd)/dashboard.sh >> $log_dir/systemguard_cron.log 2>&1" | ||
|
||
# Create log directory with error handling | ||
mkdir -p "$log_dir" | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to create log directory: $log_dir" | ||
exit 1 | ||
fi | ||
|
||
# Verify user retrieval | ||
if [ -z "$username" ]; then | ||
echo "Error: Unable to retrieve current username." | ||
exit 1 | ||
fi | ||
|
||
# Add cron job to crontab with error handling | ||
(crontab -l 2>/dev/null; echo "$cron_job") | crontab - | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to add the cron job to the crontab." | ||
exit 1 | ||
fi | ||
|
||
echo "Cron job added: $cron_job" | ||
} | ||
|
||
# Call the function to add the cron job | ||
add_cron_job |