Your question composes actually of three questions:
1) How to download a file (with auth)
2) How to upload a file (with auth)
3) How to schedule a CRON job
My first question is how do you want to store the id/passwd
ad 1) You can use both curl
and wget
depending on what is better for your use case. I recommend reading excellent post by Daniel Stenberg curl vs Wget to understand the differences (a quick summary - curl
is more developer friendly and is also a library a wget
is a command).
I'm recommending using certificates without user/passwd as such would be visible to everyone having your id or group.
In my example, I'll use curl
and certificate:
curl --cert certificate_file.pem https://example.com/example.xml
ad 2) To upload a file
curl -T example.xml --cert certificate_file.pem ftps://ftp.server.com/remotedir/
ad 3) Cron format:
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * * /usr/bin/find
You only crontab -e
to edit your crontab file. Other ways can lead to file corruption.
If you want to run your file every Thursday at 8AM do it the following way:
0 8 1-31 1-12 4 /path/your_script.sh
or you can do it with *
: 0 8 * * 4 /path/your_script.sh
.
If you want to read more do it at: Cron and Crontab usage and examples
Now put it together:
#!/bin/bash
# $1 is your command line input (e.g. example.xml)
file_download=$1
file_upload=$2
actual_download="curl --cert certificate_file.pem https://example.com/$file_download"
eval $actual_download
if [ -e "$file_upload" ] then
actual_upload="curl -T $file_upload --cert certificate_file.pem ftps://ftp.server.com/remotedir"
eval $actual_upload
else
echo "The $file_upload does not exist!"
fi
You would then execute the file:
your_script.sh /path/example_download.xml /path/example_upload.xml
Thanks, I'll try it. For Cron it's all ok. for download I have an https://www... access with user and password. On FTP it's user and password authentification too.
Filename is date of the day : https://www.domain.ltd/.../services/lqjxmlexport/export.aspx?dt=07.08.2017 (dd.mm.YYYY format)
1@Meloman: Please do :). I always recommend using certificates as it is way more secure and nobody can "steal" your credentials from plaintext. If you want to use curl with credentials
curl -u username:password https://example.com
. If it answers your question please mark it, thank you. – tukan – 2017-09-07T08:12:49.6471Yes, of course but we have no choice to use what provider of the xml gives to us, and it's simple authentification ! Even if I find it stupid since SSL is enough to keep the data confidential. Data that are not otherwise. – Meloman – 2017-09-07T08:16:16.930