-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup_files.sh
More file actions
55 lines (44 loc) · 1.63 KB
/
cleanup_files.sh
File metadata and controls
55 lines (44 loc) · 1.63 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Author: Ibrahim Ucar
# Written in: Centos 7
# Date: 29.10.2018
# Mail: ucribrahim@gmail.com
# This shell script automatically clean up files that you defined down into the variables. It's basic clean up script.
# You can set this script to CRON to make this script works every minute, hour, day, etc.
# Variables of this shell script. Define your paths of log files that will be clean up!
file1="/var/log/mylog1.txt"
file2="/var/log/mylog2.txt"
file3="/var/log/mylog3.txt"
#--------------------------------------------------------------
# We will let the "root" user execute this script. Other users will not be allowed to execute this script.
# If this feature needed then remove the "#" signs which start at the beginning of the lines.
#USERID=$(echo $UID)
#
#if [ $USERID -eq "0" ]; then
# echo "---------------------------------"
# echo "You're root. Let the boss go on!"
# echo "---------------------------------"
# else
# echo "You're not root. This script can be only executed by root user!"
# exit
#fi
#---------------------------------------------------------------
# Cleanup process. There is if condititon for three(3) files in the variables above.
if [ -f $file1 ]; then
cat /dev/null > $file1
echo "$file1 has been cleaned!"
else
echo "$file1 doesn't exists!"
fi
if [ -f $file2 ]; then
cat /dev/null > $file2
echo "$file2 has been cleaned!"
else
echo "$file2 doesn't exists!"
fi
if [ -f $file3 ]; then
cat /dev/null > $file3
echo "$file3 has been cleaned!"
else
echo "$file3 doesn't exists!"
fi