• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

How to automatically save logs before restartlog command in putty

Joined
Aug 27, 2013
Messages
800
Reaction score
1,969
This is one of the things I keep forgetting doing: SAVE THE LOGS BEFORE WIPING THEM. So, I just though that it's not too hard to make linux do the job for me and save them into 1 directory, instead of me going and copying them. Yup, still being a newbie into all this, but with a little bit of help.

There you go, a tutorial on how to do it:

P.S.S. Another tutorial for not skilled people like me :junglejane:

##### Tutorial #####

Firstly,
create a folder cabal_history in root/var/log/ directory. (Should look like this: root/var/log/cabal_history)


P.S. Sometimes, permission 0755 might not work, so set it to 0700.

Second:
Open the cabal_restartlog.sh file (in root/home/cabal directory) and you will see this:


DEFAULT:


Code:
[COLOR=#141414]#!/bin/sh[/COLOR]
[COLOR=#141414]
[/COLOR]
[COLOR=#141414]rm -f /var/log/cabal/*[/COLOR]
[COLOR=#141414]
[/COLOR]
[COLOR=#141414]countdown()[/COLOR]
[COLOR=#141414](*the rest of the script*[/COLOR]


Add these 2 lines:

Code:
[COLOR=#0000ff]mkdir /var/log/cabal_history/$(date '+%d-%b-%Y-%T')[/COLOR]
[COLOR=#0000ff]cp -r /var/log/cabal/*.log /var/log/cabal_history/$(date '+%d-%b-%Y-%T')[/COLOR]

AFTER #!/bin/sh and BEFORE rm -f /var/log/cabal/*


Which will look like this:


Code:
[COLOR=#141414]#!/bin/sh[/COLOR]
[COLOR=#141414]
[/COLOR]
[COLOR=#0000ff]mkdir /var/log/cabal_history/$(date '+%d-%b-%Y-%T')[/COLOR]
[COLOR=#0000ff]cp -r /var/log/cabal/*.log /var/log/cabal_history/$(date '+%d-%b-%Y-%T')[/COLOR]
[COLOR=#141414]rm -f /var/log/cabal/*[/COLOR]
[COLOR=#141414]
[/COLOR]
[COLOR=#141414]countdown()[/COLOR]
[COLOR=#141414](*the rest of the script*[/COLOR]






Save it and you are done.

Now, each time you will write cabal_restartlog, your old logs will be saved inside new named folder (date+time) inside the cabal_history folder you've created in the root/var/log/ directory.

credits to w3rnis
 
Back
Top