LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy
User Name
Password
Puppy This forum is for the discussion of Puppy Linux.

Notices


Reply
  Search this Thread
Old 07-06-2015, 06:58 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Copy based on date


I would like a script that would copy files based on the date.

I would only want only one copy per day.

I think that I would need a marker file to show that a copy was already made for the current day.
 
Old 07-06-2015, 07:02 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,159

Rep: Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857
What have you done for yourself so far? post your attempts and any errors.
 
Old 07-06-2015, 08:22 PM   #3
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I do not have any thing so far.

You guys really like seeing Solved. :-)
 
Old 07-06-2015, 08:33 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,789

Rep: Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951
Based on date is a bit ambiguous. You can find lots of examples of using the find command to copy files based on date. By using cron you can copy the files once a day at a certain time.

http://www.tecmint.com/35-practical-...-find-command/
 
Old 07-07-2015, 08:45 PM   #5
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
It is not what I need.

I have a script that copies files to another drive.

I want to modify it so it only copies once per day and aborts if it has already run once.
 
Old 07-07-2015, 09:06 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,789

Rep: Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951
One idea would be to create a file using the touch command after the script copies the files that uses the date as the name. Then add a if then that checks if that file exists before the copy.
 
Old 07-08-2015, 06:43 AM   #7
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
How would that work since the date is different each day ?

7-8-15.txt, 7-9.15.txt
 
Old 07-08-2015, 07:02 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,789

Rep: Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951
I really do not understand. If you have a script that copies files then only run it once a day. Since I don't know how the script actually works I just threw out an idea.

Code:
today=$( date +%F )

if [ ! -f "$today.txt" ] 
then 
  copy files
  touch $today.txt
fi
It will create a dummy file each day. Its up to you to delete them etc.

Last edited by michaelk; 07-08-2015 at 08:56 AM.
 
Old 07-08-2015, 08:52 AM   #9
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Thanks.

Do not mean to be a P.I.T.A.

Sometimes I do a shutdown more than once a day.

So if I delete the file, it will execute the script more than once a day.

This will make a file with the current date as the name.

Quote:
touch `date +m-%d-%Y-%T`.txt
How could I compare the filename with the current date and then proceed based on the comparison ?

Last edited by Fixit7; 07-08-2015 at 08:54 AM.
 
Old 07-08-2015, 09:12 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,789

Rep: Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951
Yes, if you delete file on the same day then it will execute the script again.

The code I posted will compare the current date with the filename. If the file does not exist then your script should copy the files. Adding time to the filename will overly complicate the script and from what you posted is not required.

You can add another if statement like the following after the files are copied.
Code:
yesterday=$( date --date="-1 day" +%F )

if [ -f "yesterday"] 
then
  rm $yesterday.txt
fi
 
  


Reply



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
copy all the files in the directory based on the modification date SriniKlr Programming 4 01-26-2011 10:08 AM
[SOLVED] Use date with touch to create new file with date based name craigjl Linux - Newbie 5 03-12-2010 09:46 AM
Copy by date ijf99 Linux - Newbie 1 12-17-2008 05:10 AM
copy based on date Byenary Linux - General 2 03-02-2007 04:13 PM
Date-based copy AdmiralThrawn Linux - General 2 02-23-2004 09:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy

All times are GMT -5. The time now is 05:20 AM.

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
Open Source Consulting | Domain Registration