Writing a shell script for logs movement to remote location.
Hi,
I have to write a shell script for automatic logs movement and compression weekly and monthly on remote server. So, I'm facing some problems as I am not expert in shell scripting. I have to move my sarg logs weekly from source server to destination server. Sarg logs generate daily, weekly and monthly with different names as per dates, for example-- daily logs name format--- 2013Feb02-2013Feb02 2013Feb01-2013Feb01 weekly logs name format--- 2013Jan27-2013Feb02 monthly logs name format--- 2013Jan01-2013Jan31 Now, how will I write a shell script which will move such named logs from source server to destination server? Daily and weekly logs at the end of each week and monthly logs at the end of month. What will be the syntax or pattern that will be used to catch the dates? |
I was trying to write a script but I got struck at one step-
Quote:
|
To get date formats, you can use the date cmd with the relevant options http://linux.die.net/man/1/date eg
Code:
date +%y%b%d |
Hi chrism,
I got it. I already know that date format. But my concern is what would be the code if I have to write from 1st to 7th date. For example-- I do move logs manually using this command mentioned below: Quote:
2013Feb01-2013Feb01 - 2013Feb07-2013Feb07 Then again for the next week- 2013Feb08-2013Feb08 - 2013Feb14-2013Feb14 |
Is there any update from anyone?
|
You could place all log files in 1 directory and once your script is done with movement at remote server it should move all these files from this directory to another directory so next time script will pick up whatever it founds at this directory. By doing this you dont need to worry about applying date formats of these files.
|
Quote:
Code:
Today=`date +"%Y_%m_%d"` HTH. |
Hi Habitual,
Code:
[root@proxy ~]# cat sarg_script Quote:
The output on destination server in the destination directory is as follows : Quote:
Quote:
So, my concern is why the above mentioned script is not running properly for two or more than two date's directories? I will be very thankful to you. |
Code:
ssh <dest._server_ip> 'cd /backup/$(date +"%b-%Y")/ Code:
ssh <dest._server_ip> 'cd /backup/$(date +"%Y%b%d")/ subscribed with interest... This bash? Edit: I would tar+gz locally then move stuff around via rsync. but that's just "me". |
Hi Habitual,
Quote:
I was wondering if I can make this script short. Can anyone help me, please? |
If you say it is working, who am I to argue? :)
Shorter? Probably! Have a Great Day! |
Hi Habitual,
Quote:
Thanks for your suggestion in advance. :) |
|
All times are GMT -5. The time now is 06:20 PM. |