LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-14-2016, 11:19 PM   #1
aniket mohite
LQ Newbie
 
Registered: Dec 2016
Posts: 1

Rep: Reputation: Disabled
Question 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
 
Old 12-14-2016, 11:58 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
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 \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 10:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 02:03 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration