This is just a quick post to let you see a simple batch script I have written that I run everytime I log out of my work PC. It's very simple, just cleans up a few things, the script is fully documented, but if anything isn't clear then please feel free to ask.
There a python script that is called, this is a new addition which goes through and compresses all of my putty session logs, I have a seperate log for each of my PuTTY server connections, depending on what I am doing they can grow quite large, so the script compresses and date stamps them. I can post the python script if you would like to see it.
You can download the batch file here.
@echo off
REM The above command turns off the output for the script
REM Name : logoff.bat
REM Author : Craig Richards
REM Created : 15th-April-2011
REM Version : 1.2
REM Modified : 1.1 - Changed hard coded path from C:\Documents and Settings\my name to %USERPROFILE%
REM : 1.1 - Changed the hard coded path for drive to %HOMEDRIVE%
REM : 1.2 - Added the section to call my python script to compress my puttylogs when I log off the machine
REM Instructions : From the command line, just type logoff.bat, or double click on the file in windows explorer
REM Clear all Temporary Internet Files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
REM Clear IE History
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
REM Remove all files from %TEMP% - You can get a copy of sdelete here http://technet.microsoft.com/en-us/sysinternals/bb897443
sdelete -s %TEMP%/*.*
REM Remove list of Recently opened documents - You can get a copy of sdelete here http://technet.microsoft.com/en-us/sysinternals/bb897443
sdelete "%USERPROFILE%\Recent\*.*"
REM Compress the days puttylogs - 1.2
python puttylogs.py
REM Log the date/time
echo %DATE% %TIME% >> %HOMEDRIVE%\logoff.txt
REM Log off my machine
shutdown -l -f
As always I am always interested in your thoughts so if you have any comments or feedback then please feel free to add any comments, or you can mail me here.
This is the python script I wrote to zip up my puttylogs.
# Script Name : puttylogs.py
# Author : Craig Richards
# Created : 13th October 2011
# Last Modified :
# Version : 1.1
# Modifications : 1.1 - Added the variable zip_program so you can set it for the zip program on whichever OS, so to run on a different OS just change the locations of these two variables.
# Description : Zip up all the logs in the given directory
import os # Load the Library Module
import shutil # Load the Library Module
from time import strftime # Load just the strftime Module from Time
logsdir="c:\logs\puttylogs" # Set the Variable logsdir
zipdir="c:\logs\puttylogs\zipped_logs"
zip_program="zip.exe" # Set the Variable zip_program - 1.1
for files in os.listdir(logsdir): # Find all the files in the directory
if files.endswith(".log"): # Check to ensure the files in the directory end in .log
files1=files+"."+strftime("%Y-%m-%d")+".zip" # Create the Variable files1, this is the files in the directory, then we add a suffix with the date and the zip extension
os.chdir(logsdir) # Change directory to the logsdir
os.system(zip_program + " " + files1 +" "+ files) # Zip the logs into dated zip files for each server. - 1.1
shutil.move(files1, zipdir)
os.remove(files) # Remove the original log files