I have a script in different folder. Now i want to call that script and execute that script from that path alone.
My code is
#!/bin/bash
wname=yahoo
PATH='/opt/IBM'
wac=`/usr/bin/ls $PATH | /usr/bin/grep "$wname"`
STOP=`/usr/bin/find $PATH/$wac -type f -name "stop.sh"`
/usr/bin/sh $STOP & (here i am executing the script in background)
/usr/bin/sleep 5
kill (after 5 sec it need to kill the sleep process)
Best is to use another variable name instead of PATH.PATH is a system variable and may cause issues when using otherway.
And you need not to give "&" for background process.You may call the main script in background as well
Off topic: The $PATH environment variable is reserved for the Shell. Choose another name for your environment variable ... $SEARCH ?
If you overwrite $PATH in the manner of your script, the Shell will not be able to find any command (ls / find / grep ... whatever) from that point on.
Unless you have an unusual version of ls , that output is impossible.
Anyway we now know that "yahoo" is a directory and that there is probably only one script and that it probably does not vary its location. Therefore we don't need to search.
Can the whole script be condensed to this? :
#!/bin/bash
/usr/bin/sh /opt/IBM/yahoo/stop.sh & ; PID=$?
/usr/bin/sleep 5
# Check whether we still have any background jobs
if [ -n "`jobs`" ]
then
kill $PID
fi
script name will be the same but my location will differ based upon my input... that's why i made a search and find that exact file in the script.... i need to add some more stuffs also.... thanks for your solution ...