Shell script to loop for a particular file in predefined path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to loop for a particular file in predefined path
# 1  
Old 01-13-2010
Shell script to loop for a particular file in predefined path

Hi ,
i need a shell script to poll a particular file in a predefined directory , once that file is found , i need to launch another shell script .

Eg i need to poll for A.txt in /home/username/Desktop

once A.txt is created by Desktop(Created by another Script) , i need to launch another script
# 2  
Old 01-13-2010
Code:
#!/bin/ksh

while true  #continuous loop (always true)
do
  if [ -f /home/username/Desktop/A.txt ]  # if file exists
  then  #execute these commands/script
    /execute_this_script.ksh  
  else  # file didn't exist, check back in 60 seconds
    sleep 60
  fi
done

Here's another version that will quit polling once the file is there, then executes something after. Many ways to do it, just depends on what logic you prefer.

Code:
#!/bin/ksh

until [ -f /home/username/Desktop/A.txt ]
do
  echo "file is not here yet"
  sleep 60
done

echo "it's here now"
execute_something.ksh


Last edited by 2pugs; 01-13-2010 at 11:11 AM.. Reason: Formatting
# 3  
Old 01-13-2010
well.....this may work

Code:
#!/bin/bash

# check to see if foo.txt exists in a particular user's desktop

checkpath="/home/username/desktop/foo.txt"

if [[ -e $checkpath ]]

   then echo "$checkpath already exists"
 
   else touch $checkpath
fi

sleep 5

/path/to/myscript.sh # make sure the script is executable
done


Last edited by tlarkin; 01-13-2010 at 11:10 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare user string with and predefined file...

i am trying to write shell script how to write shell script which is ask for user id and password then compare both from two different file.. i have no idea how to compare with data present in file.. #!/bin/bash -e read -p "User ID: " first read -p "Password: " second if ;then echo... (3 Replies)
Discussion started by: niko420
3 Replies

2. UNIX for Dummies Questions & Answers

Download .xls file from mail and copy to another path using shell script

Hi I have a mail attachment coming from a mail id and evreytime with the same name in .xls format.I have to download the .xls file into a location and convert it itno .csv format and copy the .csv file to another location. (1 Reply)
Discussion started by: bikky6
1 Replies

3. Shell Programming and Scripting

Setting the path permanently using shell script

I'm trying to set the path permanently through a shell script. (/opt/quest/bin:/usr/bin/lab to /.profile.) I tired using echo option like below but it doesn't work. Please suggest me the right way to do so. echo "PATH=$PATH:/opt/quest/bin:/usr/bin/lab" >> /.profile (6 Replies)
Discussion started by: pjeedu2247
6 Replies

4. Shell Programming and Scripting

Help with File processing - Adding predefined text to particular record based on condition

I am generating a output: Name Count_1 Count_2 abc 12 12 def 15 14 ghi 16 16 jkl 18 18 mno 7 5 I am sending the output in html email, I want to add the code: <font color="red"> NAME COLUMN record </font> for the Name... (8 Replies)
Discussion started by: karumudi7
8 Replies

5. Shell Programming and Scripting

A shell script for create a a file in the respective path

Hello forum members, I have to create a out file in the current path./aaa/bbb/ccc/hhh. i am writing script below. ###script Begins##### #!/bin/ksh echo "Weclome" if then echo "Hello" rm -rf $aaa/bbb/ccc/hhh #clean the exsisting o/p file echo "no... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

6. Shell Programming and Scripting

Trouble with a file path as awk output in for loop

When I run the following command in the shell it works fine. It prints a city name and then a path for a file. ~$ for i in `awk -F':' '{print $0}' /home/knoppix/Desktop/data/subs | grep -m 1 $ city | sed "s/:/ /"` >do >echo $i >done Now, when I place it in this shell script (sh) it prints... (6 Replies)
Discussion started by: afroCluster
6 Replies

7. Shell Programming and Scripting

Storing the values in text file using while loop in shell script

Hi Frdz while read line do name=`echo $line | cut -d' ' -f 1 ` password=`echo $line | cut -d`-` -f 2` name > logfile.txt password > logfile.txt done < list.txt When it is run, am getting last values in list.txt file only,it is not storing lall the list entry values. How can i... (5 Replies)
Discussion started by: KiranKumarKarre
5 Replies

8. Shell Programming and Scripting

want only file names (not whole path) in shell script

hi i wrote following script, #!/usr/bin/sh for index in `ls /tmp/common/*.txt` do echo "$index" done here index is giving full path but in my program i want only file names (not along with whole path) Eg. if in /tmp/common files are a.txt and b.txt den out should be a.txt b.txt ... (6 Replies)
Discussion started by: crackthehit007
6 Replies

9. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies

10. Shell Programming and Scripting

getting a shell script to know it's path

Is it possible in Bash (or any other shell) to get a shell script to know it's own path without having to be part of $PATH or anything like that. I need this cos i want the script to be able to rename the directory in which it resides. is this possible? (6 Replies)
Discussion started by: Nat
6 Replies
Login or Register to Ask a Question