-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate.sh
More file actions
executable file
·41 lines (31 loc) · 782 Bytes
/
rotate.sh
File metadata and controls
executable file
·41 lines (31 loc) · 782 Bytes
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
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env /bin/sh
do_rotate()
{
base_name=$1
num_backups=$2
i=$num_backups
# not using for 'for ((..))' or 'for i in {...}' syntax, its bash-only
while [ "$i" -gt 0 ] ; do
j=$((i - 1))
src_name="${base_name}.${j}"
dest_name="${base_name}.${i}"
test -e "$src_name" && mv "$src_name" "$dest_name"
i="$j"
done
test -e "${base_name}" && mv "${base_name}" "${base_name}.0"
}
fatal()
{
msg=$1
echo "$msg"
exit 1
}
base_name=$1
max_backups=$3
if [ -z "$base_name" ] ; then
fatal "Usage: $0 base_name [max_count]"
#elif [ ! -e "$base_name" ] ; then
# fatal "Fatal: $0 - couldn't find base file '$base_name'"
fi
test -z "$max_backups" && max_backups=5000
do_rotate $base_name $max_backups