diff --git a/cmd/root.go b/cmd/root.go index 63a5ec0..5bca26e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v0.1.129" +const version = "v0.1.130" // rootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ diff --git a/script.sh b/script.sh index 2c2ad1f..2666f61 100644 --- a/script.sh +++ b/script.sh @@ -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 \ No newline at end of file diff --git a/usecases/app/alert/alert.go b/usecases/app/alert/alert.go index 7d8b181..84a6205 100644 --- a/usecases/app/alert/alert.go +++ b/usecases/app/alert/alert.go @@ -7,6 +7,7 @@ import ( "os" "strings" "time" + "unicode" "github.com/ibilalkayy/flow/entities" "github.com/ibilalkayy/flow/handler" @@ -91,6 +92,7 @@ func (h MyAlert) SendAlert(category string) error { Category: category, Hours: hour, Minutes: minute, + Days: day, Weekdays: weekdayStr, } @@ -122,10 +124,15 @@ func (h MyAlert) WriteNotificationValues(av *entities.AlertVariables) error { hours := av.Hours minutes := av.Minutes + desiredDay := av.Days desiredWeekday := av.Weekdays - desiredTime := fmt.Sprintf("%d:%d", hours, minutes) + desiredTime := fmt.Sprintf("%02d:%02d", hours, minutes) + + // Convert to upper letter + if len(desiredWeekday) > 0 { + desiredWeekday = string(unicode.ToUpper(rune(desiredWeekday[0]))) + strings.ToLower(desiredWeekday[1:]) + } - // Retrieve the SCRIPT_PATH environment variable scriptPath := os.Getenv("SCRIPT_PATH") if scriptPath == "" { return errors.New("SCRIPT_PATH environment variable is not set") @@ -153,6 +160,9 @@ func (h MyAlert) WriteNotificationValues(av *entities.AlertVariables) error { if strings.Contains(line, "DESIRED_TIME=") { lines[i] = fmt.Sprintf(`DESIRED_TIME="%s"`, desiredTime) } + if strings.Contains(line, "DESIRED_DAY=") { + lines[i] = fmt.Sprintf(`DESIRED_DAY="%d"`, desiredDay) + } if strings.Contains(line, "DESIRED_WEEKDAY=") { lines[i] = fmt.Sprintf(`DESIRED_WEEKDAY="%s"`, desiredWeekday) }