Find a file and if exists , execute a different file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a file and if exists , execute a different file
# 1  
Old 07-02-2015
Find a file and if exists , execute a different file

Good Morning All,
I'm a novice and please excuse me if i did miss some of the forum rules.
What my intention is, i have a file (services) residing @ /u01/Oracle/services.
I know i can use the find command to find the "service" file. I get this file from a windows box and there is no certain time when it comes. I can use a crontab to schedule a script once its in place.
What am looking for is a suggestion to create a shell script, that lookks for the "services" file , if it exist go to a different location /u01/middleware/stop.sh and execute the stop.sh file and then delete the "services" file.
Any suggestions please?
Thanks
# 2  
Old 07-02-2015
Not sure I understand the problem correctly, but why don't you use absolute paths?
Code:
if [ -e /u01/Oracle/services ]; then /u01/middleware/stop.sh; rm /u01/Oracle/services; fi

# 3  
Old 07-02-2015
Quote:
Originally Posted by RudiC
Not sure I understand the problem correctly, but why don't you use absolute paths?
Code:
if [ -e /u01/Oracle/services ]; then /u01/middleware/stop.sh; rm /u01/Oracle/services; fi

Thank You RudiC, will give it a try and let you know.

---------- Post updated at 12:47 PM ---------- Previous update was at 11:17 AM ----------

Quote:
Originally Posted by RudiC
Not sure I understand the problem correctly, but why don't you use absolute paths?
Code:
if [ -e /u01/Oracle/services ]; then /u01/middleware/stop.sh; rm /u01/Oracle/services; fi

Thanks RudiC, i'm getting the following error
Code:
"No Such file or directory"

Thanks
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, output, and code segments.

Last edited by Don Cragun; 07-02-2015 at 04:18 PM.. Reason: Add CODE tags.
# 4  
Old 07-02-2015
That's a bit surprising. What OS and shell are you using?
# 5  
Old 07-02-2015
Quote:
Originally Posted by RudiC
That's a bit surprising. What OS and shell are you using?
GNU/LINUX, bash shell
# 6  
Old 07-02-2015
Show us the output from the command:
Code:
ls -l /u01/Oracle/services /u01/middleware/stop.sh

From the error message you showed us, I would guess that stop.sh is not there or that one of them is a symlink to a file that does not exist.
# 7  
Old 07-02-2015
Quote:
Originally Posted by Don Cragun
Show us the output from the command:
Code:
ls -l /u01/Oracle/services /u01/middleware/stop.sh

From the error message you showed us, I would guess that stop.sh is not there or that one of them is a symlink to a file that does not exist.
Thanks Don, i changed the paths and now giving the exact pasth against the original post as i wanted to put the path short. After running the command am getting this
Code:
-rw-r--r-- 1 oraphpe dba   0 Jul  2 12:49 /u01/EnvironmentStartup/testingvalidate.txt
-rwxr-x--- 1 oraphpe dba 324 Jul 25  2014 /u01/Essbase/Oracle/Middleware/user_projects/epmsystem7/bin/stop.sh

When i used the command
Code:
[ -f /u01/EnvironmentStartup/testingvalidate.txt ] && echo "File Exists"

the output was File exists
Thanks

---------- Post updated at 02:48 PM ---------- Previous update was at 02:20 PM ----------

Quote:
Originally Posted by Don Cragun
Show us the output from the command:
Code:
ls -l /u01/Oracle/services /u01/middleware/stop.sh

From the error message you showed us, I would guess that stop.sh is not there or that one of them is a symlink to a file that does not exist.
Thanks all . I finally did some trial and error and came up with the following command and it worked great.
Code:
if [ -f /u01/EnvironmentStartup/testingvalidate.txt ]; then /u01/Essbase/Oracle//Middleware/user_projects/epmsystem7/bin/stop.sh; rm /u01/EnvironmentStartup/testingvalidate.txt; fi

One more question is , i want to make it as a shell script, do i need to have this .sh at the root level?
Thanks
Moderator's Comments:
Mod Comment Please use CODE tags for all sample input, output, and code segments.

Last edited by Don Cragun; 07-02-2015 at 04:20 PM.. Reason: Add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find out whether a file exists with the help of regular expression?

Hi all I have a list of file names in array. But this file names are not exact. so i want to search whether a file exists or not using regular expression. code snippet: if ; then echo "File exists" else echo "File does not exits" fi over here "*EQST*" should be treated as a regular... (4 Replies)
Discussion started by: Ganesh_more
4 Replies

2. UNIX for Dummies Questions & Answers

Statement to find if an entry exists in a file

I need to check if an entry input by the user is in a file. If so, I need to run a command, and if it does not exist then it should output entry does not exist. So I have so far... echo "Enter record:" read record //command || //command Can I use an if statement to do this? (3 Replies)
Discussion started by: itech4814
3 Replies

3. Windows & DOS: Issues & Discussions

Script that, if file exists in Samba share, moves file to Unix server

I'm looking to do pretty much what the title says. I want a script that runs, it can run on Unix or Windows, doesn't matter, and searches a Samba shares for a .txt file. If the file exists, the script will move (or possibly copy) the file from the Samba share into a directory on our Unix... (3 Replies)
Discussion started by: twcostello
3 Replies

4. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

5. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

6. Shell Programming and Scripting

Newbie.. Find if a file exists and open, if not create the desired file..

Hey all, I'm brand new to script writing, I'm wanting to make a script that will ask for a file and then retrieve that file if it exists, and if it doesn't exist, create the file with the desired name, and I'm completely stuck.. so far.. #! bin/bash echo "Enter desired file" read "$file" if ... (5 Replies)
Discussion started by: Byrang
5 Replies

7. Shell Programming and Scripting

Verify File exists and execute command

Hi, I am trying to verify that a file exists within an alternate directory. If the file exists, it will execute a copy command...if it does not, it should exit the script. I tried the <test> command and the but keep coming up with syntax errors. I am coding in C Shell and the file... (5 Replies)
Discussion started by: CKT_newbie88
5 Replies

8. Shell Programming and Scripting

find, if exists then append for file with same name

I will have to process multiple files with same name everyday. My requirement is: If on a certain day I see that filename.txt exists then the contents of the filename.txt would be added/append to the former file contents.Each time it sees the file the content would be added.But the header ... (8 Replies)
Discussion started by: RubinPat
8 Replies

9. Shell Programming and Scripting

Need to write a script in UNIX to find a file if another file exists

So I have a lot of Java applications on my servers all having their own folder from the applications subdirectory. Now, I need to do the following. Search all the applications subdirectories for message.jar. If the message.jar file exists, I need to search the application directory for... (1 Reply)
Discussion started by: mmdawg
1 Replies

10. Shell Programming and Scripting

unix script to check whether particular file exists and to find its size

I want to find the size of particular file exists in a particular directory and i wnt to zip it. In the below mentioned code it should check the MQ.log in the particular directory.Please correct my code so that it will check for particular MQ.log but i could not able to check whether the... (9 Replies)
Discussion started by: Balachandar
9 Replies
Login or Register to Ask a Question