Sponsored Content
Full Discussion: Retry Logic But In Cron
Top Forums UNIX for Beginners Questions & Answers Retry Logic But In Cron Post 303046120 by jgt on Friday 24th of April 2020 10:58:49 AM
Old 04-24-2020
In the following, the index file is placed in the requests directory, and the image file in the temp directory. The index files can have different extensions to indicate grouping or priority.
The pid file is used to prevent subsequent invocations of the cron job from running.
You can periodically examine the contents of the temp and request directories for entries that older than some specified time.


Code:
#!/bin/ksh
cd /u/email
BATCH=$1
proc=$$
if [ -r /u/email/$BATCH.pid ]
then
    echo "Previous batch  still running" $(cat $BATCH.pid)
    exit
fi
echo $proc >/u/email/$BATCH.pid
list=$(ls requests|grep $BATCH)
if [ "$list" != "" ]
    then
    for request in $list
    do
    #do processing here          
    #if successful 
        mv requests/$request done
        mv temp/$request* done
    #else
       #echo "This one failed"
       #fi
    done
fi
rm /u/email/$BATCH.pid
echo finished at $(date)

 

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retry upon FTP failure

I am using the following code in a C Shell script to transfer files to a remote server: ftp -n logxx.xxxx.xxx.xxx.com <<DO_FTP1 quote user $user_name quote pass $password ascii put $js_file_name bin put $FinalZipFile quit DO_FTP1 This code works great except on those rare occasions... (8 Replies)
Discussion started by: phudgens
8 Replies

2. Shell Programming and Scripting

If then else - Retry operation

I need to read a file line by line, then depending on the contents of each line, type in a code that will get written to an array. The problem I have is when I ask the user to confirm the input code, if it is wrong, how do i Return to ask again? Any thing I try increments the file to the next... (6 Replies)
Discussion started by: kcpoole
6 Replies
File::Pid(3pm)						User Contributed Perl Documentation					    File::Pid(3pm)

NAME
File::Pid - Pid File Manipulation SYNOPSIS
use File::Pid; my $pidfile = File::Pid->new({ file => '/some/file.pid', }); $pidfile->write; if ( my $num = $pidfile->running ) { die "Already running: $num "; } $pidfile->remove; DESCRIPTION
This software manages a pid file for you. It will create a pid file, query the process within to discover if it's still running, and remove the pid file. new my $pidfile = File::Pid->new; my $thisfile = File::Pid->new({ file => '/var/run/daemon.pid', }); my $thisfileandpid = File::Pid->new({ file => '/var/run/daemon.pid', pid => '145', }); This constructor takes two optional paramters. "file" - The name of the pid file to work on. If not specified, a pid file located in "File::Spec->tmpdir()" will be created that matches "(File::Basename::basename($0))[0] . '.pid'". So, for example, if $0 is ~/bin/sig.pl, the pid file will be /tmp/sig.pl.pid. "pid" - The pid to write to a new pidfile. If not specified, $$ is used when the pid file doesn't exist. When the pid file does exist, the pid inside it is used. file my $pidfile = $pidfile->file; Accessor/mutator for the filename used as the pid file. pid my $pid = $pidfile->pid; Accessor/mutator for the pid being saved to the pid file. write my $pid = $pidfile->write; Writes the pid file to disk, inserting the pid inside the file. On success, the pid written is returned. On failure, "undef" is returned. running my $pid = $pidfile->running; die "Service already running: $pid " if $pid; Checks to see if the pricess identified in the pid file is still running. If the process is still running, the pid is returned. Otherwise "undef" is returned. remove $pidfile->remove or warn "Couldn't unlink pid file "; Removes the pid file from disk. Returns true on success, false on failure. program_name This is a utility method that allows you to determine what "File::Pid" thinks the program name is. Internally this is used when no pid file is specified. SEE ALSO
perl. AUTHOR
Casey West, <casey@geeknest.com>. COPYRIGHT
Copyright (c) 2005 Casey West. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2008-04-05 File::Pid(3pm)
All times are GMT -4. The time now is 05:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy