[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2014-03-04
5
Medium Priority
?
1,742 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 27

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 27

Accepted Solution

by:
skullnobrains earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Six Sigma Control Plans
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

650 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