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

Not sure I understand the problem correctly, but why don't you use absolute paths?

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 ----------

Thanks RudiC, i'm getting the following error

"No Such file or directory"

Thanks

That's a bit surprising. What OS and shell are you using?

GNU/LINUX, bash shell

Show us the output from the command:

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

-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

[ -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 ----------

Thanks all . I finally did some trial and error and came up with the following command and it worked great.

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

No, it needs to be somewhere on the PATH, or you can put it into an application directory and add this to your PATH variable.

---------- Post updated at 21:59 ---------- Previous update was at 21:58 ----------

Or you can run it specifying its full path every time.

1 Like

Thanks all for the suggestions.:slight_smile: