Created
November 29, 2021 21:55
-
-
Save hgaibor/efeaf6b8081ed5c49791dc31cec1dee8 to your computer and use it in GitHub Desktop.
Delete recordings cron task
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
#!/bin/bash | |
# Delete WAV recording files after X days. Script can be modified to match different file types or longer day interval if needed | |
# NOTE: Script below is set to dry-run, it will not delete any files until you add the -delete flag. | |
# Deletion will remove files permanently, there's no easy way to undo that. | |
# Please update the script to delete only when you confirm it it working as expected. | |
# | |
# Latest version: | |
# https://gist.github.com/hgaibor/efeaf6b8081ed5c49791dc31cec1dee8 | |
# | |
# | |
# Usage: | |
# 1. Create a bash file (.sh) preferably under asterisk user directory. | |
# 2. Change file permissions to allow execution by asterisk user | |
# 3. Call script either manually or via CRON task | |
# | |
# | |
# License: GNU GPL2 | |
# | |
# Version History | |
# 2021-11-29 First public commit by hgaibor | |
# | |
folder_path="/var/spool/asterisk/monitor" | |
log_path="/home/asterisk/cron_scripts" | |
timestamp=$(date +%Y%m%d) | |
log_file="delete_recordings-${timestamp}.log" | |
log="${log_path}/${log_file}" | |
days=14 | |
touch "${log_path}/${log_file}" | |
start_time=$(date +%s) | |
# USE THIS FOR DRY RUNS | |
find $folder_path -name "*.wav" -type f -mtime +$days -print >> $log | |
# ADD -delete for real removal | |
# find $folder_path -name "*.wav" -type f -mtime +$days -print -delete >> $log | |
echo "Deletion script -- BEGIN -- $(date +%Y-%m-%d\ %H:%M:%S)" >> $log | |
end_time=$(date +%s) | |
elapsed_time=$(( $end_time - $start_time )) | |
echo "Deletion script -- END -- $(date +%Y-%m-%d\ %H:%M:%S)" >> $log | |
echo "Elapsed Time -- $(date -d 00:00:$elapsed_time +%Hh:%Mm:%Ss) " >> $log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment