Archive for the ‘Scripts’ Category

Rename log file

Monday, August 11th, 2008

I needed to automate renaming log files because the size of the log file was slowing down the application. Here is the resulting batch file.

@echo off

set CURRDATE=%TEMP%\currdate.tmp

date /t > %CURRDATE%

set PARSEARG=”eol=; tokens=1,2,3,4* delims=/, ”
for /f %PARSEARG% %%i in (%CURRDATE%) do set YYYYMMDD=%%l%%k%%j

ren file.log file_%YYYYMMDD%.log

Batch file for account creation

Saturday, August 9th, 2008

A few years ago I automated account creation for an organization. Here is one of the scripts I sill use today.

echo off
REM Student extract processing script
REM
REM Finds the adds and deletes from the sasi export files
REM and saves them to adds.txt and dels.txt
REM
REM Alex trusler
REM
REM Please verify the GnuWin32 bin dir including CoreUtils,
REM DiffUtils, and Grep is in your path before executing script.
REM These tools are available at
REM gnuwin32.sourceforge.net
REM ——————————————————-

REM if %2 is NULL then display usage
if exist %2 goto else
echo —
echo —
echo usage: %0 [file1 old] [file2 new]
echo —
echo This script will save the output files
echo in your WORKING directory so change your directory
echo to your target directory.
echo —
echo Also, you can drag the batch file to the command window,
echo Then type a [space], then drag the old Stufile, [space]
echo then drage the new Stufile. Saves a lot of typing.
echo —
echo Please verify the GnuWin32 bin dir including CoreUtils,
echo DiffUtils, and Grep is in your path before executing script.
echo These tools are available at
echo gnuwin32.sourceforge.net
pause

goto eof
:else

REM compair the file from the last import to the current file.
sort %1 > temps1
sort %2 > temps2
diff –ignore-case temps1 temps2 > tempdiff

REM format and save the output
grep “> ” tempdiff | cut -b 3-100 > adds.txt

REM Cut the first 16 lines to match only the site and stu ID.
cut -b 1-16 temps1 > temps3
cut -b 1-16 temps2 > temps4
diff –ignore-case temps3 temps4 > tempdiff

REM format and save the output
grep “< ” tempdiff | cut -b 3-100 > dels.txt

REM clean up our garbage
del tempdiff
del temps1
del temps2
del temps3
del temps4

REM Tell the user the script has finished
echo Files adds.txt and dels.txt saved.

:eof

Stealth site

Wednesday, May 7th, 2008

I always forget the exact code to make one url frame another.

<html>
<head>
<title>insert title here</title>
</head>
<frameset rows="100%,*" border="0">
<frame src="http://www.website.com" frameborder="0">
<frame frameborder="0" noresize>
</frameset>
</html>
<!-- art -->

DD progress bar

Wednesday, May 7th, 2008

I was wiping a drive today and didn’t much care for the way dd doesn’t show anything until it’s complete.

I found this:

dd if=/dev/zero of=/dev/hda & watch -n5 -- pkill -USR1 ^dd$

–edit–
A reader posted this, but I accedentally marked him as spam.

dd if=/dev/zero of=/dev/hda & pid=$! && while kill -USR1 $pid; do sleep 15; done