Sponsored Content
Top Forums Shell Programming and Scripting Required help on a Generic File-watcher script Post 302968648 by jgt on Saturday 12th of March 2016 09:33:39 AM
Old 03-12-2016
I would approach the problem differently.
If you have control of the sending process then, have the sender put the data file in the temp directory, then put a job file in the requests directory.
The job file contains the instructions for what to do with the data file.
The job file extension is used to create separate job streams, in our instance priority.
This entire process is run as a cron job with whatever frequency you choose. We found that a long running process is too fragile, and you don't find out is not running or is hung up on something until an angry user arrives.
If you cannot have two files sent, then use 'fuser' to determine if the file is still in the process of being received, and if it is still in use, bypass it until the next iteration.

Code:
#!/bin/ksh                                                                      
PATH=/bin:/usr/bin:/usr/lib                                                     
BATCH=$1                                                                        
proc=$$                                                                         
if [ -r /u/email/$BATCH.pid ]                                                   
then                                                                            
        echo Previous job `cat /u/email/$BATCH.pid` is still running            
        exit                                                                    
fi                                                                              
echo $proc >/u/email/$BATCH.pid                                                 
cd /u/email                                                                     
list=`ls requests|grep $BATCH`                                                  
if [ "$list" != "" ]                                                            
        then                                                                    
        for request in $list                                                    
        do                                                                      
        fuser $request                                                          
        if [ $? != 0 ]                                                          
          then                                                                  
          req=`echo $request|cut -d"." -f1`                                     
          export req                                                            
          IFS="~"                                                               
          #cat requests/$request |read user email from subject memo attachments 
          cat requests/$request | read  user destination                        
          
          IFS=" "                                                               
          cd /u/email/temp                                                      
          #php emailstub.php $user $email "$subject" $memo $attachments         
          #or in your instance scp $req* $user@destination:/incoming            
          cd /u/email                                                           
          mv /u/email/temp/$req* done                                           
          mv /u/email/requests/$request done                                    
        fi                                                                      
        sleep 10                                                                
        done                                                                    
fi                                                                              
rm /u/email/$BATCH.pid

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generic Shell Script to Archive a file

Would appreciate if any one can paste a generic schell script to archive a file with date stamp by passing the file with fullpath as parameter For Eg. /apps/scripts/Archive_File.sh /data_home/project_home/file.txt this should place the file in the following directory ... (8 Replies)
Discussion started by: mak1600
8 Replies

2. Shell Programming and Scripting

generic way - help required

All, This is what I did: Suppose: $ line="23|12|21" $ eval $(echo "$line" | awk -F'|' '{print "V1="$1";V2="$2";V3="$3}') $ echo $V1 23 $ echo $V2 12 $ echo $V3 21 (3 Replies)
Discussion started by: uwork72
3 Replies

3. Shell Programming and Scripting

File Watcher

Hi Please help me in this I want to execute a shell script abc.ksh. But I only want it to execute if file XYZ is not present. If file XYZ is present than I want to unix to sleep for 5 Sec and than agaian check for XYX existence. if it sleeps for more than 30 seconds ( 6 time )I want it to... (3 Replies)
Discussion started by: er_zeeshan05
3 Replies

4. Shell Programming and Scripting

ksh script to create a generic csv file from different source formats

Hi all, I have a requirement to create a "superset" file out of a number of different sources with some different and some same columns. We intend to have a manually updateable SuperSetCols.csv which would look like "ColA","ColB","ColC","ColD","ColE","ColF","ColG" so someday we may add... (3 Replies)
Discussion started by: Leedor
3 Replies

5. UNIX for Advanced & Expert Users

Need Script for File Watcher

Hi, I need a script for "FILE WATCHER" I have in a remote FTP location server named MAIN _104 EveryDay mrng 8 i hav to search couple of folders(COL, ATT, TRA) in that FTP server (MAIN_104), and if any files are present in that folders i hav to bring back to my computer and store it anywhere... (4 Replies)
Discussion started by: nani1984
4 Replies

6. Shell Programming and Scripting

File Watcher Help !!

Hi Experts I will have be having 3 types of files in directory file1_p0_date file1_p1_date file1_p2_date As soon as it sees any of the files it needs to kick off another process and also would need the file name For this I am creating a file watcher script which will look for file1* My... (2 Replies)
Discussion started by: westernmichnov
2 Replies

7. Shell Programming and Scripting

Help needed with File Watcher script

Hi all, I am writing a script to do the following: 1) Check if there are any new <csv> files (in abc directory) to process 2) If there is new file, then perform some operation on that file. 3) Move it to a different location(after step2 is successful) 4) Do further processing on the file ... (2 Replies)
Discussion started by: stunnerz_84
2 Replies

8. UNIX for Dummies Questions & Answers

Watcher Script

Hi Guys, I hope anyone can help me on how to create a watcher-script. The script will act as watcher wherein whenever it will find an error (say the word Error) in a file, it will prompt the user. Please help! br, rymnd_12345 (3 Replies)
Discussion started by: rymnd_12345
3 Replies

9. Shell Programming and Scripting

File watcher script

if test -n "$(find/data/path/ 'filename.txst' -print-quit) then echo "file found" exit 0 else echo "file not found" exit 46 fi So I basically looking to understand the if test -n "$(find/data/path/ 'filename.txst' -print-quit) line. Pls help to elaborate what this command... (6 Replies)
Discussion started by: Nsharma3006
6 Replies

10. UNIX for Beginners Questions & Answers

Generic script to load file details(ls -ltr) in to a database.

All, I am trying to create a report on the duration of an ETL load from the file arrival to the final dump in to a database for SLA's. Does anyone have any guidance or ideas on how metadata can be extracted; information of a file: like file name, created timestamp, count of records and load... (1 Reply)
Discussion started by: pradeepp
1 Replies
cancel(1)																 cancel(1)

NAME
cancel - cancel print request SYNOPSIS
cancel [ request-ID...] [destination...] cancel -u user... [destination...] The cancel utility cancels print requests. There are two forms of the cancel command. The first form of cancel has two optional arguments: print requests (request-ID) and destinations (destination). Specifying request-ID with destination cancels request-ID on destination. Specifying only the destination cancels the current print request on destination. If desti- nation is not specified, cancel cancels the requested print request on all destinations. The second form of cancel cancels a user's print requests on specific destinations. Users can only cancel print requests associated with their username. By default, users can only cancel print requests on the host from which the print request was submitted. If a super-user has set user-equivalence=true in /etc/printers.conf on the print server, users can cancel print requests associated with their username on any host. Super-users can cancel print requests on the host from which the print request was submitted. Superusers can also cancel print requests from the print server. The print client commands locate destination information using the printers database in the name service switch. See nsswitch.conf(4), printers(4), and printers.conf(4) for details. The following options are supported: -u user The name of the user for which print requests are to be cancelled. Specify user as a username. The following operands are supported: destination The destination on which the print requests are to be canceled. destination is the name of a printer or class of printers (see lpadmin(1M)). If destination is not specified, cancel cancels the requested print request on all destinations. Specify destination using atomic or POSIX-style (server:destination), names. See for information regarding using POSIX-style des- tination names with cancel. See standards(5) for information regarding POSIX. request-ID The print request to be canceled. Specify request-ID using LP-style request IDs (destination-number). user The name of the user for which the print requests are to be cancelled. Specify user as a username. The following exit values are returned: 0 Successful completion. non-zero An error occurred. /var/spool/print/* LP print queue. $HOME/.printers User-configurable printer database. /etc/printers.conf System printer configuration database. printers.conf.byname NIS version of /etc/printers.conf. printers.org_dir NIS+ version of /etc/printers.conf. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWpcu | +-----------------------------+-----------------------------+ lp(1), lpq(1B), lpr(1B), lprm(1B), lpstat(1), lpadmin( 1M), nsswitch.conf(4), printers(4), printers.conf(4), attributes(5), standards(5) POSIX-style destination names (server:destination) are treated as print requests if destination has the same format as an LP-style request- ID. See standards(5). Some print servers send cancelation notification to job owners when their print jobs have been cancelled. This notification usually comes in the form of an email message. Cancelation notices cannot be disabled on a Solaris server. 23 Feb 2005 cancel(1)
All times are GMT -4. The time now is 06:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy