how to make a cp script
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.
Thank you |
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 { |
get log with date
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 |
Quote:
|
i have the answer in theory but i don't know how to put it in practice
|
well, since this is a trivial question, even I could provide you some help :D
Create a script file and make it executable, let's say myscript.sh (chmod 755 myscript.sh): Code:
#!/bin/sh 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 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. good luck... |
Quote:
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.
|
@chrism01:
you're right, it's better like that "YYYYMMDD_HHMMSS" so the myscript.sh should have cp line: Code:
Thank you for noticing that. |
All times are GMT -5. The time now is 04:23 AM. |