-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated the script file to include the day also
- Loading branch information
1 parent
39a8b01
commit 4ad9437
Showing
3 changed files
with
22 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Desired time in HH:MM format | ||
DESIRED_TIME="19:31" | ||
DESIRED_TIME="21:11" | ||
|
||
DESIRED_WEEKDAY="sunday" | ||
DESIRED_DAY="17" | ||
|
||
# Log file location | ||
LOG_FILE="${SCRIPT_PATH}logfile.log" | ||
|
||
# Function to install and configure NTP | ||
install_and_sync_ntp() { | ||
# Check if NTP is installed | ||
if ! command -v ntpd &> /dev/null; then | ||
echo "$(date): NTP not found. Installing NTP..." >> "$LOG_FILE" | ||
|
||
# Install NTP based on the package manager available | ||
if command -v apt-get &> /dev/null; then | ||
sudo apt-get update && sudo apt-get install -y ntp | ||
elif command -v yum &> /dev/null; then | ||
sudo yum install -y ntp | ||
elif command -v dnf &> /dev/null; then | ||
sudo dnf install -y ntp | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Start and enable NTP service | ||
if command -v systemctl &> /dev/null; then | ||
sudo systemctl start ntpd | ||
sudo systemctl enable ntpd | ||
elif command -v service &> /dev/null; then | ||
sudo service ntp start | ||
sudo update-rc.d ntp defaults | ||
fi | ||
|
||
# Force synchronize the clock immediately | ||
if command -v ntpd &> /dev/null; then | ||
sudo ntpd -gq | ||
elif command -v ntpdate &> /dev/null; then | ||
sudo ntpdate pool.ntp.org | ||
fi | ||
} | ||
|
||
# Install and synchronize NTP | ||
install_and_sync_ntp | ||
DESIRED_WEEKDAY="Monday" | ||
|
||
# Get the current time in HH:MM format | ||
CURRENT_TIME=$(date +"%H:%M") | ||
|
||
CURRENT_DAY=$(date +"%d") | ||
|
||
CURRENT_WEEKDAY=$(date +"%A") | ||
|
||
# Check if the current time matches the desired time | ||
DESIRED_WEEKDAY="sunday" | ||
if [ "$CURRENT_TIME" == "$DESIRED_TIME" ] && [ "$CURRENT_WEEKDAY" == "$DESIRED_WEEKDAY" ]; then | ||
# Run your command and log the output | ||
echo "$(date): It's time! Running the desired command." >> "$LOG_FILE" | ||
echo "$(date): It's time! Running the desired command." | ||
else | ||
echo "not set ${CURRENT_WEEKDAY} ${CURRENT_TIME} ${CURRENT_DAY}" | ||
fi |
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