0

I am using the Putty and trying to write linux commands that makes run once every day at 11pm and copy a file(flie1.seq) from one directory(xyz) to other directory(abc), the file in xyz folder has to be a current date (Like the file has to be modified or created today(current date) then it has to copy over or else ignore). Wondering if someone please help...

6
  • 1
    What have you tried yourself? Where are you getting stuck? Keep in mind, specific questions get specific answers. – mtak Mar 11 '20 at 15:22
  • Have you produced a command that does what you're after yet? Are you trying to understand how to schedule something to run daily? You're probably interested in cron (and crontab), and utilities like date. It might be possible to do what you're after in one line, or you might have to write a small script. – Attie Mar 11 '20 at 15:31
  • Thanks for the replies, I am trying to understand to write the script, so far I am using this command : cp /xyz/file1.seq /abc/. and this is just copying over the file when i run it command. eventually I am looking for something that runs this at 11pm every night and copy the file which has the current date (like today's date). I am looking to for nice way to have the syntax that does this please... – Sand123 Mar 11 '20 at 17:11
  • "eventually I am looking for something that runs this at 11pm every night".. did you not read @Attie mentioning cron ? First, write a script that does what you want, next.. use cron to run it at 11pm every night. – Señor CMasMas Mar 11 '20 at 17:42
  • Try putting together crontab, rsync and mtime – Antony Mar 11 '20 at 20:45
0

1- Switch to the user that you want to execute this sequence as.

2- Create a cronjob that will execute your command everyday at 11pm :

crontab -e

This will open a text editor where you can write your job :

3- Then copy the below snippet and save it :

00 23 * * * /bin/cp /xyz/file1.seq /abc/

4- Check that the cronjob is set :

crontab -l

PS: Note that cp will flush the timestamps automatically to the current action time : atime, mtime, ctime

2
  • Thanks for the response, I will try today putting together the scripts.. – Sand123 Mar 12 '20 at 16:03
  • let me know if the issue has been resolved. – Reda Salih Mar 12 '20 at 20:58
0

method using crontab and rsync

#m  h   dom mon dow command
00  23  *   *   *   /usr/bin/find /xyz/flie1.seq -daystart -mtime -0 -exec /usr/bin/rsync -az {} /abc/ \;

find file "flie1.seq" in path /xyz/ where

  • -daystart = from start of "today"
  • -mtime 0 = with modification time today
  • -exec rsync = execute rsync

using rsync options -az

  • a = keep attributes (except hardlinks)
  • z = compress file data during the transfer

sync to folder /abc/

rsync is very convenient and my preferred method as it easily to use if your desination is a remote server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.