I have made a bash command which generates a one liner for restarting all Weblogic ( 8,9,10) instances on a server. The script works well but I need a suggestion to make it better using the dirname concept
/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed 's/weblogic.policy//' | sed 's/security\///' | sort | sed 's/^/cd /' | sed 's/$/ ; cd .. ; \/recycle_script_directory_path\/recycle/ ;' | tr '\n' ' '
To restart a Weblogic instance, the recycle ( /recycle_script_directory_path/recycle/) script needs to be initiated from within the domain directory as the recycle script pulls some application information from some .ini files in the domain directory.
The following part of the script generates a line to cd to the parent directory of the app i.e. the domain directory
sed 's/$/ ; cd .. ; \/recycle_script_directory\/recycle/ ;' | tr '\n' ' '
I am sure there is a better way to cd to the parent directory like cd dirname but every time i run the following cd dirname command , it throws a "Variable syntax" error.
cd $(dirname '/domain_directory_path/app_name')
How do i incorporate the cd dirname in my bash command ?
Please let me know if there are any more enhancements I can do
Some info on my script
1) The following part lists out the weblogic instances running along with their full path
/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed 's/weblogic.policy//' | sed 's/security\///' | sort
2) The grep domain part is required since all domain names have domain as the suffix
To solve your problem I wrote a very basic script :
the output of pwd is fine
the output of path is dirname
Thus when you try
cd $(dirname '/domain_directory_path/app_name')
it tries to go to cd dirname ... which apparently is not thereAs I find from one of the blogs with an analogus situation :
Thus, I think
cd $($(dirname '/domain_directory_path/app_name'))
should solve your problemI tried the following script :
and the output is
One more thing
Doing a direct
cd $($(dirname '/domain_directory_path/app_name'))
did not workThus, I guess you will first need to extract the path to some variable (path in my script) and then cd to it, as I have done in my script
Regards
amRit