- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: variable directory-path for shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2011 11:26 PM
06-27-2011 11:26 PM
variable directory-path for shell script
hello,
we have a specified structure where shell scripts are located for production and test server :
test server : filesystem /test and applicationdirs like applidir1 example : /test/applidir1
prod server: filesystem /prod
test source server : filesystem /testfs/central
i want to determine in a shell script variabel the path where the application directories are located .
the shell scripts can start with absolute or relative path
example : test 1: /test/applidir1/test.sh => the directory-path is "/test"
test 2: cd /test/applidir1; ./test.sh => the directory-path is "/test"
this is my idea , with specified "case"
SCRIPT_EXEDIR=$( dirname $0 )
case "${SCRIPT_EXEDIR}" in
"/testfs/central/applidir1" ) DIREXE="/testfs/central" ;;
"/test/applidir1" ) DIREXE="/test" ;;
"/prod/applidir1" ) DIREXE="/prod" ;;
"." ) case "$( pwd -P )" in
"/test/applidir1" ) DIREXE="/test" ;;
"/prod/applidir1" ) DIREXE="/prod" ;;
"/testfs/central/applidir1" ) DIREXE="/testfs/central" ;;
esac
;;
esac
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2011 11:41 PM
06-27-2011 11:41 PM
Re: variable directory-path for shell script
It looks like that will work. You may want to handle some error cases with:
*) error here? ;;
You should remove the "" from your case patterns:
case "${SCRIPT_EXEDIR}" in
/testfs/central/applidir1) DIREXE="/testfs/central" ;;
/test/applidir1) DIREXE="/test" ;;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2011 08:17 AM
06-30-2011 08:17 AM
Re: variable directory-path for shell script
hello,
this is my final solution, i think a little bit difficult , but it handle all options of starting and
define a variable DIREXE ( it should include the first directory )
- relative path (cd /prod ; ./test.sh) DIREXE=/prod
- absolute path (/prod/test/test.sh) DIREXE=/prod
DIRNAME_SCRIPT=$( dirname $0 )
case "${DIRNAME_SCRIPT}" in
"." | ".." ) DIR_PWD=$( pwd -P )
DIRNAME_EX_APPLICATION=${DIR_PWD%/*}
case "${DIRNAME_EX_APPLICATION}" in
"/test" | "/prod" | "/testfs/central" ) DIREXE="${DIRNAME_EX_APPLICATION}"
;;
* ) DIREXE="/prod"
;;
esac
;;
* ) DIRNAME_EX_APPLICATION=${DIRNAME_SCRIPT%/*}
case "${DIRNAME_EX_APPLICATION}" in
"/test") DIREXE="${DIRNAME_EX_APPLICATION}"
;;
"/prod" ) DIREXE="${DIRNAME_EX_APPLICATION}"
;;
"/testfs/central") DIREXE="${DIRNAME_EX_APPLICATION}"
;;
".." ) DIR_PWD=$( pwd -P )
DIRNAME_EX_APPLICATION=${DIR_PWD%/*}
case "${DIRNAME_EX_APPLICATION}" in
"/test") DIREXE="${DIRNAME_EX_APPLICATION}"
;;
"/prod" ) DIREXE="${DIRNAME_EX_APPLICATION}"
;;
"/testfs/central") DIREXE="${DIRNAME_EX_APPLICATION}"
;;
* ) DIREXE="/prod"
;;
esac
;;
* ) DIREXE="/prod"
;;
esac
;;
esac
regards,