-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroll_ansible_log.sh
executable file
·32 lines (30 loc) · 1.04 KB
/
roll_ansible_log.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# -------------------------------------------------------------------------------------
# Move current Ansible log to a new name based on current date
# --------------------------------------------------------------------------------------
while IFS= read -r -d '' log_dir
do
log_name="${log_dir}/ansible.log"
if [[ ! -a "${log_name}" ]]
then
continue
fi
new_name="${log_dir}/ansible-$(date --iso-8601=date).log"
if [[ -x "${log_dir}" ]]
then
if [[ -w "${log_name}" ]]
then
if [[ ! -a "${new_name}" ]]
then
printf "Moving %s to %s ...\n" "${log_name}" "${new_name}"
mv "${log_name}" "${new_name}"
else
printf "%s already exists\n" "${new_name}"
fi
else
printf "Cannot rename %s to %s\n" "${log_name}" "${new_name}" >&2
fi
else
printf "Cannot rename %s to %s\n" "${log_name}" "${new_name}" >&2
fi
done < <(find ~ -maxdepth 4 -name logs -type d -print0)