Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 26 May 2013, 00:13
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Bash - #!/bin/sh - #!/bin/bash
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Sat 10 Mar 2012, 20:05    Post subject:  Bash - #!/bin/sh - #!/bin/bash  

I want to make backups of favorite directories and did wrote a little GUI application that does it. Now i want to make the program not to overwrite existing backups - so i want to add date and time to the file names.

How do i grep, sed or whatever needed date and time out, into a format (variable etc) that i can add easily onto a path-/file name?

Thanks for the Help

RSH

_________________
Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3843

PostPosted: Sun 11 Mar 2012, 03:04    Post subject:  

current date and time or the date the file was created?
this will give the files date@time-filename

Code:
NEWFILE=`ls -l $FILE |awk '{print $6 "@" $7 "-" $8 }'`


you may want to cp it with -p

Code:
cp -p "$FILE" "$NEWFILE" && rm "$FILE"

this will only remove the file iff the copy is succesful and will not overwrite existing files with the same date stamp and name

btw for current time use
Code:
NEWFILE="`date +%F@%T`-$FILE"

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101

Last edited by technosaurus on Sun 11 Mar 2012, 03:27; edited 2 times in total
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Sun 11 Mar 2012, 03:09    Post subject:  

technosaurus wrote:
current date and time or the date the file was created?

Current date and time is needed, but maybe others wish to get date and time of file? If you know the solution for both - hm - who knows, maybe someone else will be grateful for that?

But to me current time and date is needed.

_________________
Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3843

PostPosted: Sun 11 Mar 2012, 03:40    Post subject:  

the problem with using current date and time is that you may end up backing up files that are already backed up... so you end up with 1000s of copies of the same picture of a funny cat with different date stamps.
_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Sun 11 Mar 2012, 04:27    Post subject:  

Thank you very much!

This --> `date +%F` <-- is exactly what i needed. I just do create directories with that name and then save the files inside the directory. Very Happy

_________________
Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0394s ][ Queries: 11 (0.0035s) ][ GZIP on ]