aboutsummaryrefslogtreecommitdiffstats
path: root/src/ftpupload
blob: 01cbdb29eacdeecfcc45f214567480e5b37c1c6d (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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`

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

# upload previous 6 days for redundancy
TWODAYLOG=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='1 days ago'`"_00_00_00.log"
THREEDAYLOG=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='2 days ago'`"_00_00_00.log"
FOURDAYLOG=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='3 days ago'`"_00_00_00.log"
FIVEDAYLOG=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='4 days ago'`"_00_00_00.log"
SIXDAYLOG=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='5 days ago'`"_00_00_00.log"
SEVENDAYLOG=`/usr/bin/ftphelper --mac`"_"`date +%Y_%m_%d --date='6 days ago'`"_00_00_00.log"

# enter modbuslog directory
cd /var/modbuslog/

# move file to archive
/bin/mv $CURRENTLOG /var/modbuslog/archive/

# 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/archive/

# login to remote server and upload
/usr/bin/ftp -n -v -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $REMOTEDIRECTORY
mput $CURRENTLOG
mput $TWODAYLOG
mput $THREEDAYLOG
mput $FOURDAYLOG
mput $FIVEDAYLOG
mput $SIXDAYLOG
mput $SEVENDAYLOG
bye
EOF

EXITSTATUS=$?

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

exit $EXITSTATUS
e days. 2012-03-12Add cron.d entryJonathan McCrohan2-0/+9 2012-03-127 day rolling uploadJonathan McCrohan1-8/+22 2012-03-09Fix ftpuploadJonathan McCrohan1-1/+5 2012-03-07ReindentJonathan McCrohan1-5/+6 2012-03-07Made logs more 'English'Jonathan McCrohan1-3/+4 2012-03-07Surround log startup notice with empty linesJonathan McCrohan1-0/+2 2012-03-07Add compile time version numbersJonathan McCrohan2-1/+10 Uses git tags as version number 2012-03-05Fix copypasta errorv1.1Jonathan McCrohan1-10/+18 wrong variable used. 2012-03-05Rearrange syslog output to read 8N1 rather than N81Jonathan McCrohan1-2/+2 2012-03-05Refactor codeJonathan McCrohan2-6/+4 No source chances, reindent only. 2012-03-05Add syslog loggingJonathan McCrohan1-24/+57 2012-03-04Remove unused #define statementsJonathan McCrohan1-3/+0 2012-02-20Prune archive after 3 monthsJonathan McCrohan3-0/+7 2012-02-20Update documentationJonathan McCrohan1-3/+5 2012-02-20Add PHP to make installJonathan McCrohan1-0/+3 2012-02-20Update MakefileJonathan McCrohan1-0/+17 2012-02-20Move interval.txt to src/Jonathan McCrohan2-1/+1 2012-02-19Remove debug/testing files.Jonathan McCrohan50-4742/+0 2012-02-15Archive files after upload.Jonathan McCrohan1-0/+2 2012-02-12Fix typo in README.Jonathan McCrohan1-1/+1 2012-02-12Add ftp upload function + add documentation.Jonathan McCrohan5-3/+151 2012-01-10Handle 32bit signed overflow.Jonathan McCrohan1-1/+6 2012-01-10Update README.Jonathan McCrohan1-1/+3