ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I have a script that needs to run weekly ( I have it set using crontab) how I need to pull the dates for on the week. I have for loop set up and have the proper date splits and ready to go. However the trouble I am running into is the beginning of the month. (IE: june 3 - 7 is -4 and can be used)
So I need to figure out a way to look for a week only (subtract 7 day ) and not use any module or the very basic ones. This is a basic server that they don't want added things installed.
I want all the listings in the log file from 05/27/2008 to today which is 7 days because of may 31st. I have isolated the 03 and need to know how to use it to come up with the 27 and then look for those files. Simple enough however it is something I have no clue how to do.
# Time::Local - efficiently compute time from local and GMT time
# Time::localtime - by-name interface to Perl's built-in localtime() function
# Time::Piece - Object Oriented time objects
# Time::Piece::Seconds - a simple API to convert seconds to other date values
# Time::Seconds - a simple API to convert seconds to other date values
# Time::tm - internal object used by Time::gmtime and Time::localtime
Keep in mind that some of those have only become CORE modules since 5.10, and that many sites have not yet upgraded from 5.8. Regardless, you can easily do what you want in Core Perl (similar to what bigears posted).
use POSIX qw/strftime/;
local $\ = "\n";
$day = 60 * 60 * 24; # seconds in a day
$now = time(); # seconds since jan 1 1970
$now -= 2 * $day;
print scalar localtime($now); # perl format default
# make your own format (man strftime will tell you how)
print strftime "%D", localtime $now;