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