File detection then run script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File detection then run script
# 1  
Old 04-07-2010
File detection then run script

I am currently running 4 scripts to complete a job for me. Each script requires the finished file of the one before it. For example the first script gets the finished file called model.x, then i would like script2 to start in and use model.x as the input and get model_min.x as the finished product and so on. Is there an easy way to get this to happen all at once? THanks
# 2  
Old 04-07-2010
Hello,

You can check for existance of file using -f switch eg:
Quote:
if [ -f <file_name> ]
then
ksh <script_2>
fi
And so on.
-Nithin
# 3  
Old 04-07-2010
does this only check once or keep checking until the file is detected because it takes abot 15 minutes for the file to be created once i start the job and the file is created for script2 to be ran?
# 4  
Old 04-07-2010
My code checks only once. If you want to check periodically, pls use the function below
Code:
chk_File()
{
 wait_time=900 ;
 start_time=0 ;
 while [ $start_time -ge $wait_time ]
 do
  if [ -f $2 ]
  then
    echo "File found" ;
    ksh $1 ;
  fi
  start_time=`expr $start_time + 30` ;
done
}
chk_File script2.ksh file1.done
chk_File script3.ksh file2.done

My above function accepts 2 arguments. First one is the script to be called & second is the file from previous process. The function checks for file every 30 seconds until 15 mins(900 seconds). You can change them as per your need.
-Nithin.
# 5  
Old 04-07-2010
Im sorry im trying to get this code to run but am failing to do so. Are the lines at the bottom of your code necessary to the script to run?
Code:
chk_File script2.ksh file1.done
chk_File script3.ksh file2.done

If so how do they relate to the $1 and $2.

Also how can i tell if the "while" command is working? Thanks so much
# 6  
Old 04-07-2010
does your system support fuser? It reflects file access from various processes, and a zero count can be used to determine the file readiness...

For example:

Code:
while [[ $(fuser $file_in_use) ]] ;do echo "wait for it..." && sleep 30 ;done

Otherwise, lockfiles are always useful to serve as tie-lines for processes to check in and out with:

Code:
$ while [[ -e file_lock.txt ]] ;do echo "wait for it..." && sleep 3 ;done ;echo "done...d-done...done..."
done...d-done...done...
$ while [[ -e file_lock.txt ]] ;do echo "wait for it..." && sleep 3 ;done ;echo "done...d-done...done..."
wait for it...
wait for it...
wait for it...
wait for it...
wait for it...
wait for it...
done...d-done...done...


Last edited by curleb; 04-07-2010 at 11:07 PM.. Reason: dang-it...forgot to close the $()...!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

3. Shell Programming and Scripting

File delta detection

Hello, I need to compare two flat files (ASCII format), say file OLD and file NEW. Both have similar structure. These files are | delimitted files and have around few million of records (lines) each. Each file has same set columns and same set of key columns (i.e. the 3rd and 5th column of the... (7 Replies)
Discussion started by: manubatham20
7 Replies

4. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

5. Shell Programming and Scripting

help with email to be triggered based on fatal error detection from batch run log file neded

Hi, I require need help in two aspects actually: 1) Fatal error that gets generated as %F% from a log file say ABClog.dat to trigger a mail. At present I manually grep the log file as <grep %F% ABClog.dat| cut-d "%" -f1>. The idea is to use this same logic to grep the log file which is... (1 Reply)
Discussion started by: zico1986
1 Replies

6. Programming

Parallel Processing Detection and Program Return Value Detection

Hey, for the purpose of a research project I need to know if a specific type of parallel processing is being utilized by any user-run programs. Is there a way to detect whether a program either returns a value to another program at the end of execution, or just utilizes any form of parallel... (4 Replies)
Discussion started by: azar.zorn
4 Replies

7. Shell Programming and Scripting

need bash script Intrusion Detection on Linux

Hello all I have a script but I failed on the creation of Script is any is carried out in the shell sends the owner of the server, the message is has been implemented For example, functioned as a detection system intruders but in smaller Is it possible to help if you allow I want the... (4 Replies)
Discussion started by: x-zer0
4 Replies

8. Shell Programming and Scripting

key detection in a script

Heloo every one I want to write a script that detects a key press and mouse click and movement,but I dont know how. The second one is I want to run myscript without writing the shell ie not "sh script.sh" but "script.sh" Can you help me out of here? Thanks in advance. (9 Replies)
Discussion started by: enoch99
9 Replies

9. Shell Programming and Scripting

A simple intrusion detection script

If you have a very static Linux server and you want to make sure it's not messed with, here's a simple script that will tell you if any files have been tampered with. It's not as fancy or as secure as tripwire or those others, but it is very simple. It can be easily adapted to any *NIX OS. ... (3 Replies)
Discussion started by: otheus
3 Replies
Login or Register to Ask a Question