Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What I did was manually change the dates "*06-21.log" would be "*06-22.log" the next day.
This worked fine when I was only making backups for one machine, but now I'm doing this for 10 machines and it's starting to take up a lot of time. What I'd like to know is if there's a way to make the dates change automatically. It's difficult since the naming convention is slightly different each time. Any tips or suggestions are very welcome!
I would think if you wrote a command in there that processed the date into a variable you could simply use the variable instead of the date, and the date would come from the computer. ie
computer date ----->backupday
then change 2004-06-21.log to backupday.log
and if the folder changes as well I would think you should be able to trim the date and use the day. honestly I am not familiar with all of the commands in linux, but I am sure this can be done this way or similar, I am afraid due to my lack ok knowledge I can't tell you exactly what commands to use.
Originally posted by scheidel21 I would think if you wrote a command in there that processed the date into a variable you could simply use the variable instead of the date, and the date would come from the computer. ie
computer date ----->backupday
then change 2004-06-21.log to backupday.log
and if the folder changes as well I would think you should be able to trim the date and use the day. honestly I am not familiar with all of the commands in linux, but I am sure this can be done this way or similar, I am afraid due to my lack ok knowledge I can't tell you exactly what commands to use.
Alex
Thanks, Alex.
That's kind of what I was thinking, but I'm not sure how to factor in the different conventions for dates. I have YYYY-MM-DD, MM-DD, MMDDYY and a few different ones for other machines. *sigh*
You can insert the date in the filenames like in this example:
Code:
cp test test_$(date +%d-%m)_backup
using a $(...) construction, the output of the command inside the ( and ) is put in the filename you want to copy to. see "date --help" to list all output possibilities, any format like MM-DD-YYYY or DD-MM-YY is possible. My example above will create a file named: test_22-06_backup (it will at least today )
greetingz,
.-=~ iluvatar ~=-.
edit: here's just a list of the output possibilities for the 'date' command:
Code:
%a locale's abbreviated weekday name (Sun..Sat)
%A locale's full weekday name, variable length (Sunday..Saturday)
%b locale's abbreviated month name (Jan..Dec)
%B locale's full month name, variable length (January..December)
%c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
%d day of month (01..31)
%D date (mm/dd/yy)
%e day of month, blank padded ( 1..31)
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%p locale's AM or PM
%r time, 12-hour (hh:mm:ss [AP]M)
%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)
%S second (00..60)
%t a horizontal tab
%T time, 24-hour (hh:mm:ss)
%U week number of year with Sunday as first day of week (00..53)
%V week number of year with Monday as first day of week (01..52)
%w day of week (0..6); 0 represents Sunday
%W week number of year with Monday as first day of week (00..53)
%x locale's date representation (mm/dd/yy)
%X locale's time representation (%H:%M:%S)
%y last two digits of year (00..99)
%Y year (1970...)
%z RFC-822 style numeric timezone (-0500) (a nonstandard extension)
%Z time zone (e.g., EDT), or nothing if no time zone is determinable
Oh, awesome! I feel so stupid for not thinking of that
One other question... I might've missed it in --help, but is there a way to designate a day BEFORE? I'd have thought something like %d-1 would work, but I don't see anything for that in --help.
hmmm you want the day before... tricky one %d-1 won't work, cause it might affect %m too when going to the previous month. you can write the current date to a file
Code:
date +%d-%m > date.txt
and use this file the next day, like
Code:
cp test test_$(cat date.txt)_backup
. after making the backup, you can write the current date to the file again, wich will then be used next day etc. etc.
greetz,
.-=~ iluvatar ~=-.
ps: you can use cron jobs to automaticly put the date in the file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.