Cannot cd to parent directory with cd dirname
- by Sharjeel Sayed
I have made a bash command which generates a one liner for restarting all Weblogic ( 8,9,10) instances on a server
/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 command , it throws a "Variable syntax" error.
cd $(dirname '/domain_directory_path/app_name')
How do i incorporate the cd to the directory name in a better way ? Also are there any enhancements for my bash command
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