0

Dears ,

i want to make a schedule job in linux crowntab ,to moving (cut) files from a FTP directory to a local directory .it's not one time and should be do this every second without stopping . thanks you all very much in advance .

Arash
  • 29
  • 7
  • It seems unlikely that this is the optimal approach to any problem - please take a step back and think about what you are actually trying to achieve. – Mark Setchell Aug 08 '16 at 10:56

1 Answers1

0

You can do a loop, with crontab you can't do it because you can only fire it every minute. The other option you can try is do 60 crontabs and do this

* * * * * sh path/to/your/script
* * * * * sleep 1 && sh path/to/your/script
* * * * * sleep 2 && sh path/to/your/script
* * * * * sleep 2 && sh path/to/your/script
.
.
.
* * * * * sleep 59 && sh path/to/your/script

The other thing you can do is

while true;
do sh path/to/your/script &
sleep 1
done

This method you have to start the poller every reboot.

EDIT

Lets imagine that your script is called ftp_poller.sh and you have it in your home script folder, lets call it (/home/fitipaldi/scripts/ftp_poller.sh)

ftp_poller.sh content

 #/bin/bash
file=filename
server="example.com"
folder="where_is_the_file" #If it's in the root folder type /
user="username"
pass="supersecretpassword"
 /usr/bin/ftp -n << EOF
 open ${server}
 user ${user} ${pass}
 binary
 cd ${folder}
 get ${file}
 del ${file}
 EOF

you can do this:

* * * * * sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 1 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 2 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 3 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 4 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 5 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 6 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 7 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 8 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 9 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 10 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 11 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 12 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 13 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 14 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 15 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 16 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 17 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 18 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 19 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 20 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 21 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 22 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 23 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 24 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 25 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 26 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 27 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 28 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 29 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 30 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 31 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 32 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 33 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 34 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 35 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 36 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 37 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 38 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 39 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 40 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 41 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 42 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 43 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 44 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 45 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 46 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 47 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 48 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 49 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 50 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 51 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 52 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 53 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 54 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 55 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 56 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 57 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 58 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 59 && sh /home/fitipaldi/scripts/ftp_poller.sh

Ok, this is INSANE and I don't recommend you use this solution

But you have another solution, I think is much better

while true;
do sh /home/fitipaldi/scripts/ftp_poller.sh
sleep 1
done

This method will fire the ftp_poller.sh script, when it finish will wait 1 second and fire it again.

If you dont care if the processes can take more that 1 second and you want a lot of processes doing the same you can do

while true;
do sh /home/fitipaldi/scripts/ftp_poller.sh &
sleep 1
done

This method will fire the ftp_poller.sh script and will put it in background, then will sleep 1 second and fire it again infinitely.

Community
  • 1
  • 1
Radu Radu
  • 177
  • 16
  • could you please describe it in detail ,as i'm newbie in this ,your answer is not clear to me. thanks – Arash Aug 08 '16 at 09:44
  • Hmmm, I think this is not complicated. You have 2 ways: 1-> Do a cron job for every second calling the script wih +1 seconds of delay. 2-> Execute by your hand the script once and leave it in background in an infinite loop. Be careful because this way if 1 process dont finish the job in 1 second you will have 2 processes doing the same... Really I recommend use the second option but without putting every job in background (delete the & from the command line). I update my answer 1 sec. – Radu Radu Aug 08 '16 at 10:23
  • thanks for replay . how to connect to FTP address?how to mention destination directory? what is your exact meaning of this statement : "path/to/your/script" . – Arash Aug 08 '16 at 10:27
  • thanks a lot ,i'm more clear now .could you please let me know how to fill filename as i cant fill specific name? actually every seconds i'm receiving files like " ing_101_46763546_20160808.out" and "46763546" is the sequence number. therefore i cant set a permanent file name due to it will be changes sequentially. – Arash Aug 08 '16 at 10:54
  • Ok then the use * for the variable file `file="ing_101_*"` – Radu Radu Aug 08 '16 at 16:40