Forums » Linux

Log scripting

Nov 09, 2007 Wiggoggs link
So, this is a question about how to write a script to back up my vendetta chat logs each time I launch the game. This is my first shell script, so bear that in mind if you try to help. I only have one problem, but let me show you what the script would look like:

#!/bin/bash
mv /home/user/.vendetta/errors.log /home/user/.vendetta/Logs
vendetta

So, I would just replace my old vendetta executable with that script, and everytime I ran it, it would back up my logs and then run vendetta. But my problem is that each time I try to back up that log, it's name would conflict with the previous backed up file. So is there any way I can use the mv command or any other to rename it to the date and time at the moment the script is run. So each time it backs up, the errors.log file renames to 11/9/07_15:37, for example. Any ideas?

-Jubjub/Udjuk Marwen
Nov 09, 2007 mr_spuck link
mv ~/.vendetta/errors.log ~/.vendetta/Logs/errors-$(date +"%F-%H-%M-%S")

should work.

there's a description of the date format in dates manual if you want to change it.
Nov 12, 2007 Wiggoggs link
Thanks a bunch, mr_spuck! I'll try it when I get home from school today.
Nov 12, 2007 Wiggoggs link
Ok, I tried making the script, but there is one problem. Whenever I execute the script, I get this error message over and over again, because every time it fails, it just keeps on trying:

mv: cannot move ``~/.vendetta/errors.log' to `~/.vendetta/Logs/errors-11/12/07-15:31': No such file or directory

So the date variable is working just fine to rename the file, but there must be a syntax error in the move command, because it apparently thinks I am trying to move the file into an additional directory within Logs, instead of just renaming it once it is inside the Logs directory. Here is what my script looks like now:

#!/bin/bash
mv ~/.vendetta/errors.log ~/.vendetta/Logs/errors-$(date +"%D-%H:%M")
vendetta
Nov 12, 2007 Wiggoggs link
Haha, I finally fixed the script. Ok, there were two problems. First problem was the one I outlined in my previous post. The thing was, the format that I had the errors renaming to included the date being listed as m/d/y, but the / symbols were making the script think I was specifying the next directory to move to. So I edited the format in which the date outputed. The other problem I noticed was that the end of my script was executing the vendetta command, but since I replaced the original vendetta with the script, the script would just be trying to execute itself. So I renamed the old vendetta bin to vendetta.bak, and had my script execute that one. So here is the final format for my script:

#!/bin/bash
mv ~/.vendetta/errors.log ~/.vendetta/Logs/errors-$(date +"%b-%d-%y_%H:%M")
vendetta.bak

I'm posting all this in case anyone finds it helpful, and because I find it interesting. Yay! Thanks for your help, mr_spuck! Couldn't have done it without ya.

Jubjub/Udjuk Marwen

EDIT: I played around with the date command and figured out that your format of %F, mr_spuck, would have fixed that / problem if I hadn't changed it, so I give you full credit for that one. But I still take credit for the second problem. :P