Solved

Synology Linux Based Cron Job - FTP Connect, Move & Email

Posted on 2014-03-04
5
1,575 Views
Last Modified: 2014-04-12
Folks:

I'm a windows guru, however I have a small Synology NAS that runs some spreadsheet orders (*.xls format only) and I would like to set up a cron job that run, checks a specific folder (/volume1/TS-Orders) and looks for only a *.xls file and move the file via FTP to a Windows FTP Server that I connect to via anonymous and then e-mail me if it can or cannot process the file.

I have found a few topics here on EE however, nothing seems to work closed where you use a cron - I could be not searching for the right wording.

Here is a link I would like to do: <code>http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Q_25093871.html</code> for the e-mail if I understand it correctly.

Any help is appreciated!!
0
Comment
Question by:JustinBMak
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:AlexPace
ID: 39905547
Robo-FTP is a scriptable FTP client for Windows that can do CRON commands... the CRON command basically acts as a "sleep until X time" statement in the Robo-FTP scripting language.  I have used this to make FTP automation logic run, for example, every 15 minutes starting at 6am but only on week days.  You could do the same with a windows Scheduled Task but I preferred to do it all within the script and just leave the script running and sleeping when it wasn't transferring files.
0
 

Author Comment

by:JustinBMak
ID: 39906325
I understand, however this software seems to be for Microsoft Windows.

I am running a Synology (Linux) based NAS and people will be dropping off spreadsheets and I need them to be FTP to a Windows Server via Anonymous login/password. The FTP Service is block by IP and the hosting facility just unblocked my secondary WAN IP.

This Windows Server that I do not have any access to other than via FTP.

Thank you for the reply, however I do not see this working for me.
0
 
LVL 26

Expert Comment

by:skullnobrains
ID: 39914461
as simple as it get get with a one-liner

wput /volume1/TS-Orders/*.xls ftp://server/path/to/destination 2>&1 | mail -s yoursubject you@yourdomain.com

if you don't have wput, you can use "curl" or "ftp" or install any of these.

it is setup to send the whole output of the wput command by mail
if you need something more specific, try something along these lines

filelist=$(ls /volume1/TS-Orders/*.xls) || exit 0
for file in $filelist
do if wput "$file" ftp://...
  then mail -s "file $file was transferred successfully" you@yourdomain.com
    rm "$file"
  else mail -s "failed to transfer file $file" you@yourdomain.com
  fi
done

Open in new window


this will not send a mail if there is no xls in the source dir
it will send a simpler email
it will remove xls files that have been sent successfully

adapt to your needs and feel free to post if you need further help
0
 

Author Comment

by:JustinBMak
ID: 39957702
In order to create a script on the Synology (or Linux) to save and tested what you posted above, where do I save the file and what should the file extension be?

Sorry for such a late response, we had an addition to our family and have been a little busy with that if you know what I mean.
0
 
LVL 26

Accepted Solution

by:
skullnobrains earned 500 total points
ID: 39958732
the location of the file is quite irrelevant. you can stick it in the home directory of the user whose cron you will be using (likely root ?).

the extension is irrelevant as well, but .sh would be conventional for shell scripts. what makes it run under sh in linux/unices is either explicitely run it using "sh script_name" or use a shebang in the script and make it executable. the shebang is the first line of the file "#!/bin/sh" and is used to run the file when a non-binary executable file is launched. don't bother with it in your case, explicitly calling the script through sh is simpler

--

note that cron will mail any script output to the owner of the crontab or the mail address defined as "MAILTO=youadress@..." somewhere in the crontab regardless of the use of the mail command in the script.

bare this in mind while you cron :
test using "0 * * * * /bin/sh /path/to/script 2>&1 >/tmp/ftpcrontest.log"
and run using "...... >/dev/null"

also note that the PATH may be set to something very restrictive in cron context. you can set it in the crontab using "PATH=..." (using ':' as separator) or use absolute paths for any command that is not in the path.

----

welcome to the newly born :)
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now