LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help in script (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-in-script-4175595448/)

aniket mohite 12-14-2016 10:19 PM

need help in script
 
Hello,

i need to make script and i know basic scripting. we generate report in server every day and copy this report to perticular folder. i want to create script which transfer the file to given folder as per modification date.

ex report 14/12/2016
report 15/12/2016

if i run script in 15 dec so that script have to copy 15th dec file not 14th. same for coming days.

please help me on that

szboardstretcher 12-14-2016 10:58 PM

If you are decent with bash, you should really show your work. And share the actual filenames. That way we don't have to guess like I have here.

If they are named with the date then you can simply copy it with a date of today:
Code:

today=$(date +%d-%m-%Y)
cp report-$today /some/folder

Or if you want to copy only the newest report to a folder:
Code:

newest=$(ls -t report* | head -n1)
cp $newest /some/folder

Or if you want to get fancy and copy the newest report since 12am:
Code:

touch -t $(date +%m%d0000) /tmp/today
find . -type f -newer /tmp/today -exec cp {} /some/folder \;



All times are GMT -5. The time now is 11:01 PM.