ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hi guys.. not strong at script coding.. figure this may be simple
right now i login to the server every night and dumb the mysql database to a backup file. then i go in and delete the oldest one. client only wants say the last 10 or so kept.
Curious what would be required to write a quick little script that I can crontab to do this nightly without any personal involvment from me.
it would have to run the command line i have saved to dump the db.
I would need to know:
A) what to replace the filename with in my dump command
B) how to have the script delete any old files so that I only have about 10 in the folder at any time.
Distribution: Red Hat, CentOS, Scientific, Fedora, Ubuntu, SUSE, SLES
Posts: 14
Rep:
Linux scheduling a script
From: Farzan J Mufti July 11, 2012
The way you are trying to do is to write a script that would run as a cron job.
To delete old files you can certainly use find command. To give you a more comprehensive command I would need more information, however. You can look into the man pages by issuing command
man find
The above should take care of (B).
For (A), if you need the latest file, you can run command in your script like
LATEST_FILE=$(ls -lrt | tail -1 | awk '{print $NF;}')
Now you can use this variable in your dump command.
Hope this helps.
Last edited by Farzan Mufti; 07-11-2012 at 01:10 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.