Solved

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

Posted on 2014-03-04
5
1,669 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 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This is about my first experience with programming Arduino.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

691 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