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.
Hello; i am new in using Linux and i installed a tacacs server using centos 5 distribution, but now my boss asked me to make a periodic backup of the log file of this tacacs+ server the easiest way that i found is to use this command : cp /var/log/tacacs.log /home/tacacs1/backup/taclog`date +%y%m%d` to copy the file in another file and then create a script to run it automatically and put it in a cron to run it every week ,can someone help me on how to proceed i just have the idea but not the practical skills to do it.
That's not a good way to do it. Use logrotate as that is *exactly* what it's there for.
/etc/logrotate.d/tacacs:
Code:
/var/log/tacacs.log {
rotate 10
daily
compress
}
this will keep the last 10 days log files, automatically purging older ones, and compressing them all as it goes. I'm sure you can fine tune it from there.
Thank you very much but do you mean that i have to access the logrotate file then modify it ? and another question if i want to get the tacacs.log file of each week without deleting or compressing the last one and on each new file be named with the date do you think that this logrotate should do that?
Thank you very much but do you mean that i have to access the logrotate file then modify it ? and another question if i want to get the tacacs.log file of each week without deleting or compressing the last one and on each new file be named with the date do you think that this logrotate should do that?
Thank you
Why don't you read the docs on logrotate, which answer those questions?? Also, since you know the cp command that you need, what's preventing you from just putting it into a script file, and running it with cron??? Seems like you've got the answers to your questions already.
well, since this is a trivial question, even I could provide you some help
Create a script file and make it executable, let's say myscript.sh (chmod 755 myscript.sh):
Code:
#!/bin/sh
cp /var/log/tacacs.log /home/tacacs1/backup/taclog-$(date +"%Y-%m-%d(%H-%M-%S)")
#output is like: taclog-2011-06-23(11-11-55)
now put it into Crontab to run at desired time/day of week ... you choose when (schedule task in crontab or crontab-quick-reference)
edit Crontab: crontab -e
and if you want to execute every Friday at 1.00 AM put the following line into Crontab:
Code:
0 1 * * 5 /path/to/this/myscript.sh
save & exit with ":x"
It should do it just fine and then you will get an email with output of the execution time (or possibly error if something wrong). If you don't want emails then add >/dev/null at the end of cp line in myscript.sh
There you have it, but that's a quick and lazy way to do it, since you don't know what is done, so go for some Docs about shell scripting and the commands you want to use.
i have the answer in theory but i don't know how to put it in practice
lithos got it, but really???
The cp command was the hard part, and you already had it. You should check out one of the many, MANY bash scripting tutorials, and read the man page for crontab.
@lithos: are you sure you want () chars in a filename? It may cause issues later. If you want date & time, I usually go with this format: YYYYMMDD_HHMMSS, although going down to the 'seconds' level is usually overkill.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.