Outbound calls and play message

have updated the bash script i am currently using.

#!/bin/bash

# Function to check if it's working hours (Monday to Friday, 10 am to 6 pm)
function is_working_hours() {
    current_hour=$(date +%H)
    current_day=$(date +%u)  # 1 (Monday) to 7 (Sunday)

    if [ $current_day -ge 1 ] && [ $current_day -le 5 ] && [ $current_hour -ge 10 ] && [ $current_hour -lt 18 ]; then
        return 0  # True, it's working hours
    else
        return 1  # False, it's not working hours
    fi
}

# Function to create call files and move to the temp outbound folder and specify playback file
function create_call_files() {
    input_file="/root/gplist.txt"
    outbound_folder="/var/spool/asterisk/out/"
    dest_dir="/var/spool/asterisk/outgoing/"
    audio_file="full_path_to_your_audio_file"

    # Check if the outbound folder has more than 10 call files, and pause if necessary
    current_files=$(ls -l "$dest_dir" | grep -c '^')

    if [ "$current_files" -gt 10 ]; then
        echo "More than 10 call files in the outbound folder. Pausing the script."
        exit 0
    fi

    # Read phone numbers from the input file and create call files
    while IFS= read -r phone_number; do
        call_file="${outbound_folder}callfile_$phone_number.call"
        echo "Channel: SIP/your_sip_trunk_name/$phone_number@from-internal" > "$call_file"
        echo "Application: Playback" >> "$call_file"
        echo "Data: silence/3&$audio_file" >> "$call_file"
        echo "MaxRetries: 2" >> "$call_file"
        echo "RetryTime: 60" >> "$call_file"
        echo "WaitTime: 100" >> "$call_file"
        echo "Archive: yes" >> "$call_file"
        echo "" >> "$call_file"  # Add an empty line

        echo "Call file created: $call_file"

    done < "$input_file"
}


# Main script execution

# Check if it's working hours before generating call files
if is_working_hours; then
    create_call_files

else
    create_call_files

 #   echo "Not within working hours. Script not executed."
fi

# moving the call files from temp location to outgoing calls location(monitored by asterisk)
 
# Source and destination directories
source_dir="/var/spool/asterisk/out/"
destination_dir="/var/spool/asterisk/outgoing/"

# Check if source directory exists
if [ ! -d "$source_dir" ]; then
    echo "Source directory $source_dir does not exist."
    exit 1
fi

# Check if destination directory exists, create if not
if [ ! -d "$destination_dir" ]; then
    mkdir -p "$destination_dir"
    echo "Created destination directory: $destination_dir"
fi

# Move .call files from source to destination
for file in "$source_dir"*.call; do
    if [ -e "$file" ]; then
        mv "$file" "$destination_dir"
        echo "Moved $file to $destination_dir"
    fi
done

echo "File move completed."