bang line for stand alone tcl script

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf bang line for stand alone tcl script

  • Creator
    Topic
  • #53924
    Chuck Busch
    Participant

    I would like to write a script to do some file IO.  I would like to tcl to do this.  I would like to call this script with a Cron Job.  My quetions are:

    1.  What extension should I use in the file name.   Should it be .tcl or .tclsh

    2. What should the bang line be?

    3.  Do I need to include an additional package.

    4. When I test this can I just navigate to the directory and call the script.  Or do I need to start the tcl interpreter and then call the script or do I need to start the tclsh interpreter.

    Thanks for any help.

Viewing 7 reply threads
  • Author
    Replies
    • #79554
      Chris Williams
      Participant

      We’re running sh on Linux. We start our Tcl scripts with these three lines:

      Code:

      #! /bin/sh
      #
      exec tcl “$0” “$@”

      Unlike Windows, the routine doesn’t require an extension, but it can be anything you want. Just make sure the file is executable. The major point to remember is that cron does not create the environment. It will run as the user who submitted the job, but it doesn’t use the normal setup process that creates all of the profile variables. You are responsible for doing that. This has been discussed a number of times. Try searching for “cron”.

    • #79555
      Charlie Bursell
      Participant

      A cleaner method is:

      #!/usr/bin/env tcl   (or hcitcl or perl)

      In Unix you do not need an extention.  You must make sure root and site are set.  In Windows use .htc which does for it what the bang line does for Unix

    • #79556
      Russ Ross
      Participant

      1.  What extension should I use in the file name.   Should it be .tcl or .tclsh

      We currently use “.tcl” as our extentions for TCL scripts but it can be any extension or no extension at all, stricly your choice but best to be consistant.

      2. What should the bang line be?

      We use both previously posted methods.

      We started out using

      Code:

      #!/usr/bin/ksh
      # this line to escape the next line from the tcl interpreter
      exec hcitcl “$0” “$@”

      and now use this for newly written TCL stand-alone scripts

      Code:

      #!/usr/bin/env tcl

      3.  Do I need to include an additional package.

      Most of our standalone TCL scripts don’t need a pacakge but here is an example of one that did and how the “pacakge require” command was invoked.

      Code:

         # Require oth_unzip_oldmsgs

             if {$debug} {
                 set display_line “$module requiring package oth_unzip_oldmsgs…”
                 subroutines::display
             }
             set ret_cd [catch {set oth_unzip_oldmsgs_vers [package require oth_unzip_oldmsgs]} err]
             if {$ret_cd} {
                 set display_line “$module Error >$err$oth_unzip_oldmsgs_vers< acquired."
                     subroutines::display
                 }
             }

      Since you knew enough to ask about pacakges I will assume you understand how to access and maintain packages.

      4. When I test this can I just navigate to the directory and call the script.  Or do I need to start the tcl interpreter and then call the script or do I need to start the tclsh interpreter.

      If you put your TCL standalone script in a directory in your path and set the permission of it to be executable, you can type the name of the file from any directory at the command line prompt and it will run.

      You will not need to launch the hcitcl interperter to run a stand alone TCL script.

      Russ Ross
      RussRoss318@gmail.com

    • #79557

      Chuck, you may want to consider using a UPoC thread with advanced scheduling instead of a cron job. The script will run inside the Cloverleaf environment and so it will have access to Cloverleaf variables, etc. And this makes for easier migrations because everything is contained inside of Cloverleaf.

      From the UPOC thread, you’d call a tcl TPS proc using the TPS template. Your code will go in the time mode. Easy as pie!

      Here’s a very simple example.

      proc tps_test { args } {
      [code]proc tps_test { args } {

      -- Max Drown (Infor)

    • #79558
      Russ Ross
      Participant

      Now that Max brought to my attention your desire to run the TCL stand alone from cron, be aware that the cron envrionment is a blank slate so requires some environment setup before invoking a stand alone script.

      Here is a single example of how I run a stand alone K-shell script that calls a stand alone TCL script to build a current lookup table from a comma separated valued file maintained by the system owner.

      #
      #
      [code]#
      #

      Russ Ross
      RussRoss318@gmail.com

    • #79559
      Chuck Busch
      Participant

      Max,

      Thanks for the suggestion to use the time mode to execute my scripts.

    • #79560
      Jim Kosloskey
      Participant

      Chuck,

      No you cannot place a proc there – try the dirparse UPoC or the File Delete UPoC.

      The dirparse will get fired after a directory scan which is controlled by your Advanced Schedule. The delete only gets invoked if any files have been processed.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #79561

      Chuck, fileset-local is a protocol used for scanning a directory and reading in files.

      What you probably need is the UPoC protocol instead of the fileset-local protocl. The UP0C protocol runs on the timer and executes whatever script you specify. In order to add the script, place it in the tclprocs directory, and then it must be included in the tcl index, so you’d want to either open it and save it in the script configurator or run mktclindex inside the tclprocs directory.

      -- Max Drown (Infor)

Viewing 7 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,435
Topic Tags
286
Empty Topic Tags
10