aboutsummaryrefslogtreecommitdiffstats
path: root/src/ftpupload
blob: 05ae60e0a03183613df0cdec7ff5192abe16bbe8 (plain)
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
#!/bin/sh

# ftpupload
#
# Copyright (C) 2012 Jonathan McCrohan

USERNAME=`/usr/bin/ftphelper --username`
PASSWORD=`/usr/bin/ftphelper --password`
SERVER=`/usr/bin/ftphelper --server`
REMOTEDIRECTORY=`/usr/bin/ftphelper --directory`

# local file to be uploaded 
FILE=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='1 days ago'`"_00_00_00.log"

# mput is dumb, and if we don't cd to the directory,
# it will try to save file to /var/modbuslog/MAC.....log on ftp remote
cd /var/modbuslog/

# login to remote server and upload
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $REMOTEDIRECTORY
mput $FILE
bye
EOF

# move file to archive
mv $FILE /var/modbuslog/archive/

# remove files after 3 months
CLEANUP="/var/modbus/archive/"`/usr/bin/ftphelper --mac`"_"`date +%Y_%m --date='4 months ago'`"*.log"
rm $CLEANUP