10px^2 spacer

helper scripts

this is a collection of most of my "helper scripts", (mostly) windows batch scripts, which help generate some of this site's markup and content.

thumbnails are cropped, scaled-down versions of the original image.  to see the un-cropped, full-size original image, which will open in a new window, click its respective thumbnail.

these shell scripts can be considered organic by their lack of dependencies, as in they only call shell commands or other shell scripts (which also only call shell commands).  with a few regional tweaks (e.g. date specific ones), these scripts should work on (at least) any nt based version of windows (i.e. windows nt through windows 10), save for links.sh, which should work on (at least) any typical install of a popular "desktop" linux distro supporting kernel 2.6.


blog_index_bat

blog.index.bat

this script generates blog.index.xml, an index of every blog posting.  it systematically works backwards through the subnavigation menu on rantings.and.ravings.html to find these blog postings.


blog_updates_bat

blog.updates.bat

this script generates blog.updates.xml rss link, an rss feed of the 25 most recent blog postings.  it systematically works backwards through the subnavigation menu on rantings.and.ravings.html to find these 25 most recent blog postings.


fixfilename_bat

fixfilename.bat

this script takes in a filename (e.g. file name) and processes it, outputting a url encoded filename (e.g. file%20name).

expand/collapse fixfilename.bat
typically this script is called from within another script.  for example:

for /f "tokens=*" %%b in ('call fixfilename.bat %%~nxa') do set _file=%%b

:: fixfilename.bat
::
:: Script to add HTML entities to Windows filenames when necessary for
:: compatibility with XML documents.
::
:: nerpter77.com
:: (C)MMXIII Ickis, nerpter77.com.  All rights reserved.

@echo off

setlocal enabledelayedexpansion

set _old_filename=%*
set _n=0

:start
call set _s=%%_old_filename:~!_n!,1%%

if not defined _s goto :exit

if !_s! equ ^  goto :replace_space

if !_s! equ ‚ goto :replace_eacute

::if !_s! equ \ goto :replace_backslash

if !_s! equ ^; goto :replace_semicolon

if !_s! equ @ goto :replace_at

::if !_s! equ ^& goto :replace_ampersand

if !_s! equ ^= goto :replace_equal

if !_s! equ + goto :replace_plus

if !_s! equ $ goto :replace_dollar

::if !_s! equ , goto :replace_comma

if !_s! equ { goto :replace_left_bracket

if !_s! equ } goto :replace_right_bracket

::if !_s! equ ^^ goto :replace_caret

if !_s! equ [ goto :replace_left_square_bracket

if !_s! equ ] goto :replace_right_square_bracket

if !_s! equ ` goto :replace_backtick

if !_s! equ # goto :replace_pound

if !_s! equ ^%% goto :replace_percent

set /a _n+=1
set _new_filename="%_new_filename%!_s!"

for /f "tokens=*" %%a in (%_new_filename%) do set _new_filename=%%~a

goto :start

:replace_space
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^ 

set /a _n+=1
goto :start

:replace_eacute
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^é

set /a _n+=1
goto :start

:::replace_backslash
::for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a/
::
::set /a _n+=1
::goto :start

:replace_semicolon
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^&#59;

set /a _n+=1
goto :start

:replace_at
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^@

set /a _n+=1
goto :start

:::replace_ampersand
::for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^&
::
::set /a _n+=1
::goto :start

:replace_equal
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^=

set /a _n+=1
goto :start

:replace_plus
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^+

set /a _n+=1
goto :start

:replace_dollar
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^$

set /a _n+=1
goto :start

:::replace_comma
::for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^,
::
::set /a _n+=1
::goto :start

:replace_left_bracket
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^{

set /a _n+=1
goto :start

:replace_right_bracket
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^}

set /a _n+=1
goto :start

:::replace_caret
::for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^^
::
::set /a _n+=1
::goto :start

:replace_left_square_bracket
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^[

set /a _n+=1
goto :start

:replace_right_square_bracket
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^]

set /a _n+=1
goto :start

:replace_backtick
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^`

set /a _n+=1
goto :start

:replace_pound
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^#

set /a _n+=1
goto :start

:replace_percent
for /f "tokens=*" %%a in ('echo "%_new_filename%"') do set _new_filename=%%~a^%

set /a _n+=1
goto :start

:exit
echo !_new_filename!

fixpath_bat

fixpath.bat

this script takes in a relative windows path (e.g \relative\path), outputting a relative linux path (e.g. /relative/path).

expand/collapse fixpath.bat
typically this script is called from within another script.  for example:

for /f "tokens=*" %%b in ('call fixpath.bat \!_s:~%_root_length%!%%~nxa') do set _nix_path=%%b

:: fixpath.bat
::
:: Script to "*nixify" Windows file paths.
::
:: nerpter77.com
:: (C)MMXI Ickis, nerpter77.com.  All rights reserved.

:: before
::
::  \images\favicon\77.white.ico
::
:: after
::
::  /images/favicon/77.white.ico

@echo off

setlocal enabledelayedexpansion

set _old_path=%*
set _n=0

:start
call set _s=%%_old_path:~!_n!,1%%

if not defined _s goto :exit

if !_s! equ \ goto :replace

set /a _n+=1
set _new_path=%_new_path%!_s!
goto :start

:replace
set _new_path=%_new_path%/
set /a _n+=1
goto :start

:exit
echo !_new_path!

image_sitemap_bat

image.sitemap.bat

this script generates image.sitemap.xml, an image sitemap of the images embedded (not the images linked) on content pages, both primary and secondary.  the sitemap, sitemap.xml, is systematically worked through to find the primary content pages, those primary content pages' subnavigation menus are worked through to find the secondary content pages.

there are over 80 pages and over 800 images embedded on those over 80 pages making an index of such, detailing descriptions and their page and folder locations, best left to automation.


metadata_bat

metadata.bat

this script outputs select metadata from select content pages, both primary and secondary, including xml pages (e.g. for redirection to a test file for examination or processing by another script).  this is to help ensure uniformity of that metadata throughout each content page.

some new content pages are created from similar copies of existing content pages and when this process is done manually, mistakes can be made.


println_bat

println.bat

this script takes in a line number of a document, outputting the text of that line which is between <p> (paragraph) tags.  if that line specified does not have text between paragraph tags, it'll read ahead until it finds a line that does.

expand/collapse println.bat
typically this script is called from within another script.  for example:

for /f "tokens=1 delims=" %%d in ('call println.bat %%~nxa %%c') do (   set _s=%%d   echo [%date% %time%] DESCRIPTION: !_s!   echo     ^<description^>!_s!^</description^>>>blog.updates.xml )

:: println.bat
::
:: Prints a specific line from a file.
::
:: nerpter77.com
:: (C)MMXIII Ickis, nerpter77.com.  All rights reserved.

@echo off

setlocal enabledelayedexpansion

set _n=%2

if not defined _n set _n=0

if !_n! leq 1 (
  for /f "tokens=1 delims=" %%a in (%1) do (
    set _s=%%a
    set _s=!_s:~0,3!

    if "!_s!" == "<p>" (
      set _s=%%a
      set _s=!_s:~3!
      set _s=!_s:~0,-4!

      echo !_s!
      exit /b
    )
  )
)

if !_n! gtr 1 (
  for /f "skip=%2 tokens=1 delims=" %%a in (%1) do (
    set _s=%%a
    set _s=!_s:~0,3!

    if "!_s!" == "<p>" (
      set _s=%%a
      set _s=!_s:~3!
      set _s=!_s:~0,-4!

      echo !_s!
      exit /b
    )
  )
)

publish_bat

publish.bat

this script makes calls to those other scripts which generate stand-alone static content and not content used to help generate static content.  those scripts being:

the output of the called scripts are logged to publish.log text link.  both the line and byte counts of each generated xml file are output as verification.

one script to run them all... them all as in them all i'd run for generating stand-alone static content that is.  yes, that was a j(r^2)t reference of sorts, albeit a poor one but one nonetheless.  it's more elegant than the alternative:

cd directory1 && script1.bat && script2.bat && ... script6.bat && cd .. && script7.bat >> script.log

is that not inelegance at its worst... err, best?


expand/collapse publish.bat

:: publish.bat
::
:: Script to generate automated static XML content.
::
:: nerpter77.com
:: (C)MMXV Ickis, nerpter77.com.  All rights reserved.

@echo off

echo  _________________________________________________________
echo ^|                                                         ^|\
echo ^|                           t               777777 777777 ^|^|
echo ^| n nn   eee  r rr  p pp  ttttt  eee  r rr      7      7  ^|^|
echo ^| nn  n e   e rr  r pp  p   t   e   e rr  r    7      7   ^|^|
echo ^| n   n eeeee r     p   p   t   eeeee r       7      7    ^|^|
echo ^| n   n e     r     pp  p   t   e     r      7      7     ^|^|
echo ^| n   n  eeee r     p pp     tt  eeee r     7      7      ^|^|
echo ^|                   p                                     ^|^|
echo ^|_________________________________________________________^|^|
echo \_________________________________________________________\^|
echo.
echo %~n0%~x0
echo.

cd html

echo [%date% %time%] GENERATING '/html/sitemap.xml'.
call sitemap.bat>../publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" sitemap.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c sitemap.xml ^| findstr /c:"sitemap.xml"') do echo [%date% %time%] BYTES: %%a

echo.
echo [%date% %time%] GENERATING '/html/image.sitemap.xml'.
call image.sitemap.bat>>../publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" image.sitemap.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c image.sitemap.xml ^| findstr /c:"image.sitemap.xml"') do echo [%date% %time%] BYTES: %%a

echo.
echo [%date% %time%] GENERATING '/html/video.sitemap.xml'.
call video.sitemap.bat>>../publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" video.sitemap.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c video.sitemap.xml ^| findstr /c:"video.sitemap.xml"') do echo [%date% %time%] BYTES: %%a

echo.
echo [%date% %time%] GENERATING '/html/blog.index.xml'.
call blog.index.bat>>../publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" blog.index.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c blog.index.xml ^| findstr /c:"blog.index.xml"') do echo [%date% %time%] BYTES: %%a

echo.
echo [%date% %time%] GENERATING '/html/blog.updates.xml'.
call blog.updates.bat>>../publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" blog.updates.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c blog.updates.xml ^| findstr /c:"blog.updates.xml"') do echo [%date% %time%] BYTES: %%a

echo.
echo [%date% %time%] GENERATING '/html/validate.xml'.
call validate.bat>>../publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" validate.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c validate.xml ^| findstr /c:"validate.xml"') do echo [%date% %time%] BYTES: %%a

cd ..

echo.
echo [%date% %time%] GENERATING 'updates.xml'.
call updates.bat>>publish.log

for /f "tokens=3 delims=: " %%a in ('find /c /v "" updates.xml') do echo [%date% %time%] LINES: %%a

for /f "tokens=3 delims= " %%a in ('dir /-c updates.xml ^| findstr /c:"updates.xml"') do echo [%date% %time%] BYTES: %%a

echo.
echo [%date% %time%] COMPLETED.

::pause
::exit

random_background_bat

random.background.bat

this script generates a text file, random.background.array.txt text link.  this script searches for specific background images, those prefixed with background.me. (e.g. background.me.img_2196.jpg new window internal link), in the /images/backgrounds/ folder.  the contents of this text file is then cut-and-pasted into the RandomBackgroundImage() function defined in global.js text link as the elements of an array.


sitemap_bat

sitemap.bat

this script generates sitemap.xml, a sitemap.  this script works systematically through the navigation of template.html, the template upon which every primary content page is made.


toc_bat

toc.bat

this script generates a separate text file for each content page, both primary and secondary.  the content of these text files are the list items (<li>) for an unordered list (<ul>) comprised of the sections of that page, a table of contents as it's called.  it systematically works through all html pages in the /html/ folder, scanning the section headers, if present.  this can be cut-and-pasted into the table of contents (toc).


unfixpath_bat

unfixpath.bat

this script takes in a relative linux path (e.g /relative/path), outputting a relative windows path (e.g. \relative\path).

expand/collapse unfixpath.bat
typically this script is called from within another script.  for example:

for /f "tokens=1" %%a in ('call unfixpath.bat !_html_file!') do set _html_file=%%a

:: unfixpath.bat
::
:: Script to "Windowsfy" *nix file paths.
::
:: nerpter77.com
:: (C)MMXI Ickis, nerpter77.com.  All rights reserved.

:: before
::
::  /images/favicon/77.white.ico
::
:: after
::
::  \images\favicon\77.white.ico

@echo off

setlocal enabledelayedexpansion

set _old_path=%*
set _n=0

:start
call set _s=%%_old_path:~!_n!,1%%

if not defined _s goto :exit

if !_s! equ / goto :replace

set /a _n+=1
set _new_path=%_new_path%!_s!
goto :start

:replace
set _new_path=%_new_path%\
set /a _n+=1
goto :start

:exit
echo !_new_path!

updates_bat

updates.bat

this script generates updates.xml rss link, an rss feed of the 100 most recently added or modified files, with a healthy amount of exclusions.

this helps me as well as any curious felines which may be, well, curious.


validate_bat

validate.bat

this script generates validates.xml, a "one-stop shop" of a document from which to verify the integrity of both the html and css of every content page, both primary and secondary.  this script works in the same manner as sitemap.bat, with links to w3c markup validators (i.e. w3c markup validator new window external link for xhtml/html5 and w3c css validator new window external link for css, duh).  it systematically works through the sitemap, sitemap.xml.

having over 80 pages of html with linked css can be quite the chore when you need to navigate through primary and secondary content pages.  having all those content pages with links to validators makes this a less involved chore.


video_sitemap_bat

video.sitemap.bat

this script generates video.sitemap.xml, a video sitemap of the videos embedded on secondary content video pages.  videos.html has its sub navigation systematically worked through to find secondary content video pages (which are html5, not xhtml) that have (as they should) embedded videos.  these being videos defined inside a <source> tag.

despite there being few pages and few videos embedded on those pages, indexing of such, detailing titles, descriptions and their page and folder locations best left to automation.


links_sh

links.sh

this script, a linux shell script, leverages both wget and grep to systematically work though published urls on links.html, validating their availability and format, highlighting any changes since last publish.


expand/collapse links.sh

#!/bin/sh

# links.sh
#
# Script to parse and test links from links.html.  Links are tested for
# availability and change of protocol and/or path.
#
# nerpter77.com
# (C)MMXXIV Ickis <ickis@nerpter77.com>.  All rights reserved.

echo " _________________________________________________________"
echo "|                                                         |\\"
echo "|                           t               777777 777777 ||"
echo "| n nn   eee  r rr  p pp  ttttt  eee  r rr      7      7  ||"
echo "| nn  n e   e rr  r pp  p   t   e   e rr  r    7      7   ||"
echo "| n   n eeeee r     p   p   t   eeeee r       7      7    ||"
echo "| n   n e     r     pp  p   t   e     r      7      7     ||"
echo "| n   n  eeee r     p pp     tt  eeee r     7      7      ||"
echo "|                   p                                     ||"
echo "|_________________________________________________________||"
echo "\\_________________________________________________________\\|"
echo ""
echo $0
echo ""

url="http://nerpter77.com/html/links.html"

echo "Downloading document \"$url\" to memory..."

command=`wget $url -qO- | grep "<li>" | grep -o ">http[s]\?://[a-zA-Z0-9\./%_\-]\{1,\}<" | grep -o "http[s]\?://[a-zA-Z0-9\./%_\-]\{1,\}"`

if [ "$command" = "" ]; then
  echo "Download failed."
  exit
else
  echo "Download succeeded."
fi

echo "Parsing hyperlinks from document in memory..."

IFS=$'\n' links=($command)

c=0

while [ "x${links[c]}" != "x" ]; do
  links[c]=`echo ${links[c]}`
  ((c++))
done

if [ "$c" -gt 0 ]; then
  echo "Parsing succeeded.  Hyperlinks parsed: $c."
  echo "Testing hyperlinks...."

  c=0

  while [ "x${links[c]}" != "x" ]; do
    command=`wget --spider --no-check-certificate -nv -t 1 -T 10 ${links[c]} 2>&1`
    link=`echo $command | grep -o "http[s]\?://[a-zA-Z0-9\./%_\-]\{1,\}"`
    status=`echo $command | grep -o " [0-9]\{3\} [a-zA-Z0-9 \.]\{2,\}$" | sed 's/^ //'`

    if [ "$status" = "" ]; then
      status="Error with connection to site."
    fi

    if [ "$link" != "" ]; then
      if [ "${links[c]}" != "$link" ]; then
        echo "$((c + 1)). ${links[c]}  -->  $link  $status"
      else
        echo "$((c + 1)). ${links[c]}  $status"
      fi
    else
      echo "$((c + 1)). ${links[c]}  Error connecting to site."
    fi

    ((c++))
  done

  echo "Testing complete."
else
  echo "Parsing failed."
  exit
fi

©mmxxiv ickis, ickis@nerpter77.com mail link.  all rights reserved.  updates rss linkprivacy policy.