"how to test crontab job" Code Answer's

You're definitely familiar with the best coding language Cobol that developers use to develop their projects and they get all their queries like "how to test crontab job" answered properly. Developers are finding an appropriate answer about how to test crontab job related to the Cobol coding language. By visiting this online portal developers get answers concerning Cobol codes question like how to test crontab job. Enter your desired code related query in the search bar and get every piece of information about Cobol code related question on how to test crontab job. 

how to test crontab job

By riffrazorriffrazor on Jan 12, 2021

# crontest
# See https://github.com/Stabledog/crontest for canonical source.

# Test wrapper for cron tasks.  The suggested use is:
#  1. When adding your cron job, use all 5 stars to make it run every minute
#  2. Wrap the command in crontest
#  Example:
#  $ crontab -e
#     * * * * * /usr/local/bin/crontest $HOME/bin/my-new-script --myparams
#  Now, cron will run your job every minute, but crontest will only allow one
#  instance to run at a time.  
#  crontest always wraps the command in "screen -d -m" if possible, so you can
#  use "screen -x" to attach and interact with the job.   
#  If --bashdb is used, the command line will be passed to bashdb.  Thus you
#  can attach with "screen -x" and debug the remaining command in context.
#   - crontest can be used in other contexts, it doesn't have to be a cron job.
#       Any place where commands are invoked without an interactive terminal and
#       may need to be debugged.
#   - crontest writes its own stuff to /tmp/crontest.log
#   - If GNU screen isn't available, neither is --bashdb

lockfile=$(if [[ -d /var/lock ]]; then echo /var/lock/crontest.lock; else echo /tmp/crontest.lock; fi )
useScreen=$( if which screen &>/dev/null; then echo true; else echo false; fi )
screenBin=$(which screen 2>/dev/null)

function errExit {
    echo "[-err-] $@" | tee -a $crontestLog >&2

function log {
    echo "[-stat-] $@" >> $crontestLog

function parseArgs {
    while [[ ! -z $1 ]]; do
        case $1 in
                if ! $useScreen; then
                    errExit "--bashdb invalid in crontest because GNU screen not installed"
                if ! which bashdb &>/dev/null; then
                    errExit "--bashdb invalid in crontest: no bashdb on the PATH"

                return 0
                return 0

if [[ -z  $sourceMe ]]; then
    # Lock the lockfile (no, we do not wish to follow the standard
    # advice of wrapping this in a subshell!)
    exec 9>$lockfile
    flock -n 9 || exit 1

    # Zap any old log data:
    [[ -f $crontestLog ]] && rm -f $crontestLog

    parseArgs "$@"

    log "crontest starting at $(date)"
    log "Raw command line: $@"
    log "Inner args: $@"
    log "screenBin: $screenBin"
    log "useBashdb: $( if $useBashdb; then echo YES; else echo no; fi )"
    log "useScreen: $( if $useScreen; then echo YES; else echo no; fi )"

    # Were building a command line.

    # If screen is available, put the task inside a pseudo-terminal
    # owned by screen.  That allows the developer to do a "screen -x" to
    # interact with the running command:
    if $useScreen; then
        cmdline="$screenBin -D -m "

    # If bashdb is installed and --bashdb is specified on the command line,
    # pass the command to bashdb.  This allows the developer to do a "screen -x" to
    # interactively debug a bash shell script:
    if $useBashdb; then
        cmdline="$cmdline $(which bashdb) "

    # Finally, append the target command and params:
    cmdline="$cmdline $innerArgs"

    log "cmdline: $cmdline"

    # And run the whole schlock:


    log "Command result: $res"

    echo "[-result-] $(if [[ $res -eq 0 ]]; then echo ok; else echo fail; fi)" >> $crontestLog

    # Release the lock:

Source: stackoverflow.com

Add Comment


All those coders who are working on the Cobol based application and are stuck on how to test crontab job can get a collection of related answers to their query. Programmers need to enter their query on how to test crontab job related to Cobol code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to test crontab job for the programmers working on Cobol code while coding their module. Coders are also allowed to rectify already present answers of how to test crontab job while working on the Cobol language code. Developers can add up suggestions if they deem fit any other answer relating to "how to test crontab job". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to test crontab job resolved professionally and stay updated to the latest Cobol updates. 

Cobol answers related to "how to test crontab job"

View All Cobol queries

Cobol queries related to "how to test crontab job"

Browse Other Code Languages