Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I want to know how to run a task at the last day of every month, whethwer it has 31, 30 days or whatever. it's to update a MySql db (The Worst Database In The World, no contest
Thanks in advance.
I'll include a cron header to make it easy to explain.
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands
Thanks guys, answer is perfect,
This thread just shows how much I still need to learn. i'm a sysadmin/programmer so I'm learning different date syntax all the time (i've got to remember MySql/Php/Linux/C/God Knows What else) It's a little daunting sometimes. But I'll just do what i always do: wing it! As you've probably guessed formal logic is a euphamisim for "Don't know what the hell i'm doing"
I've just re-read man:crontab(5) & man:cron(8) & I'm surprised there is no "Last of Month" feature. IMO, this is a bug.
If you run your script at 1:13 am, as suggested, won't you be doing your update before the beginning of business? I would expect that anything that needs to be done on the last day of the month needs to be done after the close of business. If that is the case, why not run your script at 1:13 am on the 1st of the month.
BTW, what is the purpose of the db update you're tasked w/ doing?
This also works, notice here I'm using d/m/y instead of m/d/y.
# GET FIRST DAY OF LAST MONTH
FIRST=$(date --date "last month" +01/%m/%Y)
# USE FIRST DAY OF THIS MONTH TO GET LAST DAY OF LAST MONTH.
LAST=$(date --date "`date +%m/01/%Y` yesterday" +%d/%m/%Y)
echo "FIRST $FIRST"
echo "LAST $LAST"