Sponsored Content
Operating Systems AIX Script to perform some actions on multiple files Post 302076221 by heprox on Saturday 10th of June 2006 01:39:28 AM
Old 06-10-2006
Question Script to perform some actions on multiple files

I have this Korn script that I wrote (with some help) that is run by cron. I basically watches a file system for a specific filename to be uploaded (via FTP), checks to make sure that the file is no longer being uploaded (by checking the files size), then runs a series of other scripts. The script is in a never ending loop that is "throttled" so that it when it is finding matching files its loop is shorter, but once it stops finding mathing files (in the monitored file system) it slow down until it finds another matching file.

Everything works great except that now I need to have the script monitor the same filesystem for two filenames. Actually they are the same filename but sometimes they are in ALL CAPS and sometimes they are not (for example I might get an upload.0002 or an UPLOAD.0002). Here is the script:

Code:
#!/bin/ksh
#
# Function : is_file_arrived file
# Arg(s)   : file = file to verify
# Output   : None
# Status   : 0 = yes file arrived, 1 = no
# Env.     : IFA_WAIT : interval (secs) for file size check (def=5)
#
 
is_file_arrived() {
   [ -z "$1" ] && return 1
   local file=$1
   local arrived=1
   local size1 size2
   if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
      size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
      sleep ${IFA_WAIT:-15}
      size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
      [ ${size1:-1} -eq ${size2:-2} ] && arrived=0
   fi
   return $arrived
}
 
 
processFile ()
{
   local fileName=$1
   local fileExtension=$2
   local fileNewName="/datafiles/str${fileExtension}.asc"
   local filePrintPath="/print"
   local fileTmpPath="/tmp"
   local fileODIName="str${fileExtension}.pos"
   mv -Eignore $fileName $fileNewName      # Add status check
   prepup $fileNewName $fileExtension
   mv -Eignore  $filePrintPath/$fileODIName $fileTmpPath/$fileODIName
   save2tmp $fileExtension
   call_siu $fileExtension
}
 
# Main Processing
 
nsec=1
#hile :
while [[ "$(date +%H%M)" -lt 2329 ]]
do
   for fileName in /datafiles/UPLOAD.[0-9][0-9][0-9][0-9]
   do
      fileExtension=${fileName#*.}
      is_file_arrived "$fileName" && nsec=1 && processFile $fileName $fileExtens
ion
   done
   sleep $nsec
   case $nsec in
      1)   nsec=15;;
      15)  nsec=45;;
      45)  nsec=90;;
      90)  nsec=300;;
      300) nsec=600;;
      600) nsec=900;;
      *)   nsec=1800;;
   esac
done

...how can I add additional filenames to the expression:

Code:
for fileName in /datafiles/UPLOAD.[0-9][0-9][0-9][0-9]

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Perform a command to multiple files

How do I perform a command to multiple files? For example, I want to look at all files in a directory and print the ones that do not contain a certain string. How do I go about doing this? (4 Replies)
Discussion started by: mcgrawa
4 Replies

2. Shell Programming and Scripting

Need help on Mulitple files mutliple actions

Hi all, I have mistkanely gzipped twice an entire folder and sub folders, and also renamed the files during that process. I am trying to undo this, and I need help to create the batch to work on it. All folders are under my images directory, I have a output.txt file that holds all the... (1 Reply)
Discussion started by: saariko
1 Replies

3. Shell Programming and Scripting

Perform a set of actions for a specific file type

Hello, I have a problem that I'm having quite a bit of trouble with. I am trying to create a script that performs a specific sequence of actions for a file of a specific type. This is an abbreviated version of my basic script: #!/bin/sh #coulombic calculations... (2 Replies)
Discussion started by: oehtus
2 Replies

4. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

5. UNIX for Advanced & Expert Users

awk - remove block of text, multiple actions for 'if', inline edit

I'm having a couple of issues. I'm trying to edit a nagios config and remove a host definition if a certain "host_name" is found. My thought is I would find host definition block containing the host_name I'm looking for and output the line numbers for the first and last lines. Using set, I will... (9 Replies)
Discussion started by: mglenney
9 Replies

6. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

7. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

8. Shell Programming and Scripting

perform actions at specific locations in data frame

Hi everyone, I got a data frame like the one below and and would like to do the following: Ignore the first 3 rows and check in all following rows the second position. If the value is >500, subtract 100. Example DF: ABC 22 DE 12 BCD 223 GH 12 EFG 2104 DH ... (4 Replies)
Discussion started by: TuAd
4 Replies

9. Shell Programming and Scripting

Shell script to perform appending of .sql files

Hi, We are having multiple .sql files generated programatically which is not containing.. create or replace -- at the start and / -- at the end We need to append those .sql files with the above 2 statements at their respective positions. We will be really thankful to get responses... (6 Replies)
Discussion started by: Rami Reddy
6 Replies

10. Shell Programming and Scripting

awk script to perform an action similar to vlookup between two csv files in UNIX

Hi, I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files. Here are the contents of the two files: File 1: Date,ParentID,Number,Area,Volume,Dimensions 2014-01-01,ABC,247,83430.33,857.84,8110.76... (9 Replies)
Discussion started by: Prit Siv
9 Replies
csx_ModifyWindow(9F)					   Kernel Functions for Drivers 				      csx_ModifyWindow(9F)

NAME
csx_ModifyWindow - modify window attributes SYNOPSIS
#include <sys/pccard.h> int32_t csx_ModifyWindow(window_handle_t wh, modify_win_t *mw); INTERFACE LEVEL
Solaris DDI Specific (Solaris DDI) PARAMETERS
wh Window handle returned from csx_RequestWindow(9F). mw Pointer to a modify_win_t structure. DESCRIPTION
This function modifies the attributes of a window allocated by the csx_RequestWindow(9F) function. Only some of the window attributes or the access speed field may be modified by this request. The csx_MapMemPage(9F) function is also used to set the offset into PC Card memory to be mapped into system memory for paged windows. The csx_RequestWindow(9F) and csx_ReleaseWin- dow(9F) functions must be used to change the window base or size. STRUCTURE MEMBERS
The structure members of modify_win_t are: uint32_t Attributes; /* window flags */ uint32_t AccessSpeed; /* window access speed */ The fields are defined as follows: Attributes This field is bit-mapped and defined as follows: WIN_MEMORY_TYPE_CM Window points to Common Memory area. Set this to map the window to Common Memory. WIN_MEMORY_TYPE_AM Window points to Attribute Memory area. Set this to map the window to Attribute Memory. WIN_ENABLE Enable Window. The client must set this to enable the window. WIN_ACCESS_SPEED_VALID AccessSpeed valid. The client must set this when the AccessSpeed field has a value that the client wants set for the window. AccessSpeed The bit definitions for this field use the format of the extended speed byte of the Device ID tuple. If the mantissa is 0 (noted as reserved in the PC Card 95 Standard), the lower bits are a binary code representing a speed from the list below. Numbers in the first column are codes; items in the second column are speeds. 0 Reserved: do not use 1 250 nsec 2 200 nsec 3 150 nsec 4 100 nsec 5 - 7 Reserved: do not use It is recommended that clients use the csx_ConvertSpeed(9F) function to generate the appropriate AccessSpeed values rather than manually perturbing the AccessSpeed field. RETURN VALUES
"small and bold">CS_SUCCESS Successful operation. CS_BAD_HANDLE Window handle is invalid. CS_NO_CARD No PC Card in socket. CS_BAD_OFFSET Error getting/setting window hardware parameters. CS_BAD_WINDOW Error getting/setting window hardware parameters. CS_BAD_SPEED AccessSpeed is invalid. CS_UNSUPPORTED_FUNCTION No PCMCIA hardware installed. CONTEXT
This function may be called from user or kernel context. SEE ALSO
csx_ConvertSpeed(9F), csx_MapMemPage(9F), csx_ReleaseWindow(9F), csx_RequestWindow(9F) PC Card 95 Standard, PCMCIA/JEIDA SunOS 5.10 19 Jul 1996 csx_ModifyWindow(9F)
All times are GMT -4. The time now is 08:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy