Execute script if a file is found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute script if a file is found
# 1  
Old 12-15-2011
Execute script if a file is found

I'm trying to get the following to look for the newest powerpoint presentation and if it finds something then run a shell script named star_presentation.sh and if it doesn't then simply exit.

Any help would be greatly appreciated.


Code:
#!/bin/bash

ppts=/ticker/powerpointshare
find $ppts -mmin -1 -type f -iname "*.ppt"
exit

# 2  
Old 12-15-2011
Code:
#!/bin/bash

ppts=/ticker/powerpointshare

if [[ $(find $ppts -mmin -1 -type f -iname "*.ppt" ) ]] 
then
  ./do_you_script.sh
else
  exit
fi

# 3  
Old 12-15-2011
If the presentation script has the filename as a parameter. Also assuming that your "find" is correct (-mmin -1 ???).

Code:
#!/bin/bash
ppts="/ticker/powerpointshare"
find $ppts -mmin -1 -type f -iname "*.ppt" | while read filename
do
         /path_to-script/star_presentation.sh "${filename}"
done

# 4  
Old 12-15-2011
find does not return a non-zero when it finds no files, only when there is an error like EPERM or the directory does not exist. That's what POSIX says. You should use text output from the command to trigger the script.

Code:
ok=$(find . -name '*.ppt' -mmin -1 -exec echo 'found' \; )
[  "$ok" = "found"  ]  && ./do_your_script.sh

or

Code:
find . -name '*.ppt' -mmin -1  |
while read fname
do
   ./do_your_script.sh
   break
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execute shell script and if string found while executing then exit

Hi All, I have one shell script start.sh which executes another shell script test.sh something like below :test.sh -param1 -param2 In the test.sh there is one command for removing file:rm file1.bak I want whenever I execute start.sh, it will execute test.sh and if it finds string rm... (7 Replies)
Discussion started by: ORAI
7 Replies

2. UNIX for Dummies Questions & Answers

File Not found - Bash script

I'm facing issues in executing the bash script of mine. This script will pick the latest file received and connects SFTP server and files is placed on this remote server. Error message Enter password: "File movement" sftp> cd Test sftp> put Test_File_201309.txt File "Test_File_201309.txt"... (6 Replies)
Discussion started by: parpaa
6 Replies

3. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

4. UNIX for Dummies Questions & Answers

File not found handling in ftp script

I have a pattern for filename to be searched. I need to get the files from remote server Who are matching the file pattern. And i need to exit with non zero return code for: 1)No files found matching that pattern 2)More than one files matching the name pattern. If only one files is... (1 Reply)
Discussion started by: pandeesh
1 Replies

5. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

6. Shell Programming and Scripting

How to execute a script without giving x permission to the file?

How to execute a script with out giving x permission to the file? (7 Replies)
Discussion started by: praveen_b744
7 Replies

7. UNIX for Dummies Questions & Answers

if $LOGIN found in file then execute X - help!

Hello, I'm trying to do specific actions based on whether a string is contained within a file or not. More specifically, I'm using the $LOGIN variable to compare to a user_list plain text file to determine what auto login process to execute for the specific user. I've seen several posts using... (0 Replies)
Discussion started by: bd_joy
0 Replies

8. Shell Programming and Scripting

Continue Script when File Found

Hello All, I am trying to write a script that will only continue executing my script if a file exits. I know the directory of the file, so its just a matter of seeing if the file exists yet. If the file has not yet been created, I want the script to wait 10 minutes (600 seconds) and try again.... (7 Replies)
Discussion started by: Jose Miguel
7 Replies

9. Shell Programming and Scripting

Want to execute rest of the script after the file is ready ...

Hi All I have a requirement like, where a file gets generated in a particular dir and once the file is ready and available then I want to execute rest of the script, because untill and unless the file exists and is available there is no use of running rest of the commands in that script. ... (5 Replies)
Discussion started by: csaha
5 Replies

10. Shell Programming and Scripting

How to execute a .sql file with shell script

hi everybody... can anyone help me in executing the .sql file with shell scripting.... thanx in advance (2 Replies)
Discussion started by: abuanas
2 Replies
Login or Register to Ask a Question