-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcronjob.sh
22 lines (15 loc) · 828 Bytes
/
cronjob.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
crontab -e # opening cron editor
# run cronfunc function on every month's first hour
* 1 1 * * cronfunc
# defining cronfunc function and it's tasks
cronfunc(){
cd '/cronassets/' # entering the folder where all files exist
mkdir tempfolder # creating a directory to temporariliy store sorted files
for x in *.JPG *.jpg *.TIF *.tif *.PNG *.png *.BMP *.bmp *.GIF *.gif *.IMG *.img *.JPEG *.jpeg ; # run a loop for files having extension of these format
do
mv x tempfolder # adding images to a folder after sorting
done
timestamp = date +%b-%d-%y # Timestamp var to show when the backup was done
tar -cvf ./backups/backedup-$timestamp.tar.gz /tempfolder #backing up the directory where sorted files are kept
rmdir tempfolder # deleting the file sorted directory after backup is done
}