Reputation: 11
Please, I am sorry to bother you with my questions but I have two question that i will like to have the input of an expert.
Question : 1
We have two linux based server that received incoming file from users and another server that we store those file in it I would like to know is there a way to automate the file transfer, let me explain myself here .
I want to know if it's possible for the file to be transferred to our asset server as soon as the user upload it and after that it should be deleted from the server.
Is there any method you can advise me to use I am new to Linux world but I have a programming background ,but was thinking about a bash but don't really know how to go about it.
Question 2 :
Is it possible to create a bash to automate file installation from online server.
Thank you your help will be appreciate.
Upvotes: 1
Views: 261
Reputation: 279
the classic solution for your both question is bash script and crontab
.
bash script will automate the file transfer and crontab will make it to be schedule when you like.
#!/bin/bash
scp -r /path/to/upload_files user@destination_IP:/path/to/upload/files
in order to set cronjob:
crontab -e
Upvotes: 0
Reputation: 98
I will give a generalised answer.
You could trigger a script on upload, or if that's not possible for some reason, then Linux has a couple of notify
APIs that a command can use to watch
a directory.
Once that's done, you will need to transfer the file. Again, more than one way of doing this, but some possibilities would be scp
, sftp
, or an HTTP POST (maybe using curl
). If using scp
/sftp
, you should use key based authentication rather than passwords.
If, (and only if I presume) that worked successfully, you would want to remove the file (if it didn't, perhaps you could use the mail
command to complain to someone and/or use the mv
command to move the problem file into another directory).
If you wanted to use bash to automate some of this, then you should look at some of the following bash features:
&&
will execute the following command if the preceding command succeeded (returned with an exit code of 0)||
will execute the following command if the preceding command failed (exit code != 0)if then fi
while do done
Finally, on my system, the following command show some tools you might want to look into:
apt-cache search inotify
-
incron - cron-like daemon which handles filesystem events
inosync - notification-based directory synchronization daemon
inoticoming - trigger actions when files hit an incoming directory
inotify-hookable - blocking command-line interface to inotify
inotify-tools - command-line programs providing a simple interface to inotify
gamin - File and directory monitoring system
clsync - live sync tool based on inotify, written in GNU C
entr - Run arbitrary commands when files change
lsyncd - daemon to synchronize local directories using rsync
iwatch - realtime filesystem monitoring program using inotify
... one of those might just do everything you need out of the box...
Upvotes: 1