Giovanni Perego
A simple web site on some software of mine


Software - Bash

Note: all scripts and libraries in this section have a name starting with "jh" (my sign); there are two reasons: the first is that I can always find my scripts on a Linux system simply writing "jh" and hitting the Tab key twice. The second reason is that it is really difficult that a script of mine can "cover" (= mask) - in Path search - a program residing on a system, since rarely I have seen common programs starting with those characters.

Library identifiers: in library sources, names of exported identifiers always comply the following rule. Characters starting each word of the library name, are used to determine a sign that is the prefix of exported identifier. For instance, the library named "SomeLibName", will export identifiers as "SLNOpen()", "SLNClose()", "SLN_MODULE_VER", etc.




jhbashdebug 1.6


Description: Simple debugger for Bash scripts

Program Help:
Usage: jhbashdebug [-hHV] [-b S L] [-t F] [-w V] [-P O] <Script> [ScriptParams]
Simple debugger for Bash scripts written as Bash script (cannot debug itself).
The only external programs needed are: cat, grep, rm. If found ".jhbashdebugrc"
in curr. dir or home (or "jhbashdebugrc" in /etc) is used to load some default.
  -b  add a breakpoint for the source <S> at line <L> (-b can be repeated)
  -h  display this help and exit
  -H  display the debugging command help and exit
  -P  toggle the preference <O> (-P can be repeated)
  -t  append the trace of execution to the file <F.trc>
  -V  print version information and exit
  -w  add a watch for the variable <V> (-w can be repeated)


Screenshot (Help on commands):


Screenshot (List source, Instant watch, Step into, Instant watch):


Screenshot (List source, Step into, Step into, List source, Call stack):


Screenshot (step Out, List source, Breakpoints, Run):


Screenshot (List source, Breakpoints, show variable Values, Run):


External links:

project page on SourceForge

Previous versions: 1.51





jhchown 20120724


Description: Change owner and group inside the specified tree, if original files match specified old owner and group

Program Help:
Usage:
  jhchown <OldUser>[:[OldGroup]] <NewUser>[:[NewGroup]] <Dir> [-t]

Inside the tree starting at <Dir>, change entries with <OldUser>:<OldGroup> to
<NewUser>:<NewGroup>; if a ':' is specified without the group, then user group
is obtained from system; if test mode switch (-t) is appended, then operations
are not executed but just printed; an undo file is always created in /tmp.





jhdelolder 20130408


Description: Delete file older than a specified number of days, inside a directory tree; tree details can be specified in a config file or on command line

Program Help:
usage: jhdelolder <ConfigFile> <Days>    or
       jhdelolder <SearchRootPath> <SearchDirName> <AtDepth> <Sub> <Days> [Run]

With the first syntax, deletes files older than <Days> days and residing inside
directory trees specified in <ConfigFile>.
With the second syntax, the directory tree roots are <
SearchDirName>; these
roots are searched inside the path
<SearchRootPath>, limiting the search at
<AtDepth> levels

Previous versions: 20110303





jhfilelockobj 1.0 (object)


Description: Handles lock files (and pid files) as objects, dealing with their timeout, lock file max live time, optional error messages and optional log messages (with log level and tag)

Program Help:
jhfilelockobj 1.0; Open Source library on March 12, 2013 by J.Hubb.

Syntax, if called at shell prompt:
  jhfilelockobj <FunctionName> [FuncParam0 [FuncParam1 [...]]]

Defined functions:
  FLODone(LockPath)                    - Remove lock file and pid
  FLOGetLockPid(LockPath)              - Return pid of LockPath creator
  FLOGetPidPath(LockPath)              - Return pid path related to LockPath
  FLOInit(LockPath, PidPath, WaitTOut, - Try to create the lock file, using
          LockLiveTime, LiveTimeMsg,     timeout, checking lock live time and
          LogLevel, LogTag)              logging it; if ok, create pid file
  FLOVer()                             - Return lib. version number

Functions description:
function FLODone()
Remove the specified lock file and the related pid file if needed.


function FLOGetLockPid()
Returns the pid of the process that created the lock file.


function FLOGetPidPath()
Returns the pid path of the specified lock file.


function FLOInit()
Checks if a lock file exists; if not, creates it and returns, otherwise returns an error code, checking - if requested - the age of lock file found, and printing and logging the specified message.


function FLOResult()
Returns and prints the error code of the last module function called.


function FLOVer()
Prints the library version number.






jhglobal 20130301


Description: Repeats a specified command in a directory searched inside a tree

Program Help:
Usage:
The directory {SearchDirName} is searched starting from {StartSearchPath}; if

found, the command (copy, del, ...) is executed on specified files.
  jhglobal {StartSearchPath} {SearchDirName} copy {SrcFilePath} {NewFileName}
  jhglobal {StartSearchPath} {SearchDirName} del {FileName} (no confirm!)
  jhglobal {StartSearchPath} {SearchDirName} grep {RegExp(-i)} {NameWithWilds}
  jhglobal {StartSearchPath} {SearchDirName} list {NameWithWilds}
  jhglobal {StartSearchPath} {SearchDirName} ren {OldName} {NewName}
  jhglobal {StartSearchPath} {SearchDirName} repl {SrcFilePath} {DestFileName}
  jhglobal {StartSearchPath} {SearchDirName} rmtree {DirTreeName} (no confirm!)


Previous versions: 20120523





jhiniutil 1.01 (library)


Description: Functions to handle configuration files with Windows .ini format

Program Help:
jhiniutil 1.0.1; Open Source library on July 30, 2012 by J.Hubb.

Syntax, if called at shell prompt:
  jhiniutil <FunctionName> [FuncParam0 [FuncParam1 [...]]]

Defined functions:
  IUInit(IniPath)                        - Return complete path for IniPath
  IUReadSection(IniPath SectName)        - Read all variable names of a section
  IUReadSections(IniPath)                - Read all section names
  IUReadSectionValues(IniPath SectName)  - Read all var. assignments of a sect.
  IUReadVar(IniPath SectName VarName Def)- Read the value of a variable
  IUSectionExists(IniPath SectName)      - Check if a section exists
  IUVarExists(IniPath SectName VarName)  - Check if a variable exists
  IUVer()                                - Return lib. version number


Functions description:
function IUInit()
Prints the path for $1; if not specified a complete path, the .ini is searched in IU_ini_path, (default is current directory, user home, /etc); if not found, prints "/dev/null" and returns $IU_NOT_FOUND. No extension is added.


function IUReadSection()
Prints all variable names of the section $2, each one on a different row. Returns $IU_NOT_FOUND on file not found.


function IUReadSections()
Prints all section names, each one on a different row. Returns $IU_NOT_FOUND on file not found.


function IUReadSectionValues()
Prints all variable assignments (var. name = value) of the section $2, each one on a different row. Returns $IU_NOT_FOUND on file not found.


function IUReadVar()
Prints the value of the variable named $3, in the section $2; if the variable does not exist, it prints the default value $4. Returns $IU_NOT_FOUND on file not found.


function IUResult()
Returns and prints the error code of the last module function called.


function IUSectionExists()
Returns $IU_NO_ERROR if the section $2 exists in the file $1, otherwise returns $IU_NOT_FOUND.


function IUVarExists()
Returns $IU_NO_ERROR if the variable named $3, in the section $2 exists in the file $1, otherwise returns $IU_NOT_FOUND.


function IUVer()
Prints the library version number.


Previous versions: 1.0





jhnumcopiesps 20130708


Description: creates a new file starting from the PostScript file <PsFileName> and inserting PostScript instructions to produce more copies (as specified in <NumCopies>) of the print file; the PostScript file must contain a single copy print

Program Help:
Usage: jhnumcopiesps <PsFileName> <NumCopies >= 2>





jhpathutil 1.0 (library)


Description: Functions to handle dir and path names

Program Help:
jhpathutil 1.0; Open Source library on July 31, 2012 by J.Hubb.

Syntax, if called at shell prompt:
  jhpathutil <FunctionName> [FuncParam0 [FuncParam1 [...]]]

Defined functions:
  PUFindFilePath(Filename, PathList)- Search Filename in Pathlist and return it
  PURealDir(Dir)                    - Return the complete path for Dir
  PURealPath(Filepath)              - Return the complete path for Filepath
  PURemoveExt(Filepath)             - Return Filepath without extension
  PUResult()                        - Return error code of last function called
  PUVer()                           - Return lib. version number

Functions description:
function PUFindFilePath()
Search the filename $1 in path list $2 (colon separated); if $1 is found then its path is printed, otherwise $PU_NOT_FOUND is returned.
Example: to find and load a library: . `PUFindFilePath jhpathutil .:/bin`

function PURealDir()
Prints the complete path for directory $1; if $1 cannot be verified (since it does not exist) then the path returned is not shortened.


function PURealPath()
Prints the complete path for file $1; if $1 directory cannot be verified (since it does not exist) then the path returned is not shortened.


function PURemoveExt()
Removes the extension of the file path $1 and prints it.
Example: to load a .conf file: . `PURemoveExt $0`.conf

function PUResult()
Returns and prints the error code of the last module function called.


function PUVer()
Prints the library version number.






jhps 20090906


Description: small wrapper for ps command, that let specify a filter string

Program Help:
ps wrapper; by J.Hubb
usage: jhps [FilterString]






jhresettreeattr 20120622


Description: resets owner, group and permissions on the list of directory trees specified in the file jhresettreeattr.conf or in the file [ConfigFile]; an undo file is created in /tmp

Program Help:
usage: jhresettreeattr [ConfigFile]





jhrunevery 20100222

Description: Executes a command every <Times> times it is executed

Program Help:
Usage: jhrunevery <Times> <Command> [CommandParameters]
Run the command <Command> with optional parameters [CommandParameters], but only every
<Times> executions, otherwise jhrunevery exits.





jhstrutil 1.1 (library)


Description: Functions for string manipulation

Program Help:
jhstrutil 1.1; Open Source library on July 31, 2012 by J.Hubb.

Syntax, if called at shell prompt:
  jhstrutil <FunctionName> [FuncParam0 [FuncParam1 [...]]]

Defined functions:
  SUCmpVerNum(Ver1 Ver2)- Compares two version numbers
  SUCmpVerStr(Ver1 Ver2)- Compares two version strings
  SUToLower(Str)        - Convert Str to lower case
  SUToUpper(Str)        - Convert Str to upper case
  SUTrimLeft(Str Char)  - Trim every Char at the beginning of Str
  SUTrimRight(Str Char) - Trim every Char at the end of Str
  SUVer()               - Return lib. version number

Functions description:
function SUCmpVerNum()
Compares two strings $1 and $2 containing two version numbers in the form a[.b[.c[...]]], where a, b, c, ... are integers (not integers are treated as 0); prints -1, 0, +1 if $1 is <, =, > $2.


function SUCmpVerStr()
Compares two strings $1 and $2 containing two version strings in the form aa[.bb], where aa and bb are strings (other appended strings are ignored); prints -1, 0, +1 if $1 is <, =, > $2.


function SUResult()
Returns and prints the error code of the last module function called.


function SUToLower()
Prints the input string $1 with all characters converted to lowercase.


function SUToUpper()
Prints the input string $1 with all characters converted to uppercase.


function SUTrimLeft()
Prints the input string $1 with beginning characters removed if equal to the specified character $2.


function SUTrimRight()
Prints the input string $1 with ending characters removed if equal to the specified character $2.


function SUVer()
Prints the library version number.


Previous versions: 1.0 - 1.0.1





jhtestdns 20100531

Description: Test a specified subnet registered in a DNS, to check that direct and reverse resolutions match

Program Help:
Usage: jhtestdns <subnet in the form x.y.z>





jhtreebackup 2.11


Description: Makes a backup of trees of directories as specified in BackupSet file (see also jhtreerestore script)

Program Help:
Usage: jhtreebackup [-hV] <BackupSetPath>
Backup directory trees specified in BackupSet. This file must be executable.
For details see remarks inside a BackupSet file.
  -V  print version information and exit






jhtreerestore 2.0


Description: Restores a backup of a tree of directories, restoring the tree root with its owner and permissions; it is possible to restore the tree to another tree root (see also jhtreebackup script)

Program Help:
Usage: jhtreerestore [OPTION]... <TgzPath> <DestDir>
Restore to <DestDir> the backup in <TgzPath> file (for incremental backups,
<TgzPath> must be the prefix before '-').

Options:
  -V                     print version information and exit
  -d <OwnAndGrp> <Perm>  create <DestDir> and set owner and permission (using
                         chown and chmod commands)
  -t <ExpectedType>      check that <TgzPath> is of <ExpectedType> type (can
                         be 'incr' or 'full')






jhtunneld 20111003

Description: Open tunnels according to /etc/jhtunneld.conf; can be used as a RedHat system service script

Program Help:
Usage: jhtunneld {start|stop|status|restart|reset}
Loads tunnels specified in /etc/
jhtunneld.conf





jhuptime 20091102

Description: Logs uptime values on shutdown; can be used as a RedHat system service script

Program Help:
Usage: jhtunneld {stop|status|log}
Logs uptime values




About me



Software