Bug 55994 - enhancement for jmeter.sh startup script
Summary: enhancement for jmeter.sh startup script
Status: RESOLVED DUPLICATE of bug 21695
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.10
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-13 04:31 UTC by James Liang
Modified: 2014-01-14 17:49 UTC (History)
0 users



Attachments
enhanced jmeter.sh (2.17 KB, text/plain)
2014-01-13 04:31 UTC, James Liang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Liang 2014-01-13 04:31:49 UTC
Created attachment 31199 [details]
enhanced jmeter.sh

Hi guys,

The bin/jmeter.sh script will fail to launch if it is called via symlink or called from outside of bin.

Adding the following snippet of script will resolve the true path, cd to it, and then start jmeter.  I've attached full script with the enhancements.

-------------

#! /bin/sh
## ...

# add the following starting line 32
# resolve the true full path (e.g. called from outside of bin, called via symlinks, and etc.)
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

echo "start jmeter.sh from $DIR"
cd "$DIR"

# the rest of jmeter.sh
...
Comment 1 Sebb 2014-01-13 17:19:39 UTC
(In reply to James Liang from comment #0)
...
> #! /bin/sh
> ## ...
> 
> # add the following starting line 32
> # resolve the true full path (e.g. called from outside of bin, called via
> symlinks, and etc.)
> SOURCE="${BASH_SOURCE[0]}"

That is specific to the Bash shell.

However, there are systems where /bin/sh is not the Bash shell.

For example, on a Ubuntu system I am currently using, Bash is at /bin/bash whereas /bin/sh is the Bourne shell. On another system /bin/sh is indeed Bash.

The script must cater for the minimum supported command set.
Comment 2 James Liang 2014-01-13 21:00:53 UTC
Can we put the following at top of the script?  Bash is the most common shell.  I think that should be good enough.  Otherwise, it may not be worthwhile to go too far for the lowest common denominator.

#! /bin/bash


Also, just to clarify, should I make these simple code change in the source control?  I don't have a preference either way.  I don't know what is the right etiquette for contributing code changes.
Comment 3 Sebb 2014-01-13 22:53:37 UTC
(In reply to James Liang from comment #2)
> Can we put the following at top of the script?  Bash is the most common
> shell.  I think that should be good enough.  Otherwise, it may not be
> worthwhile to go too far for the lowest common denominator.
> 
> #! /bin/bash

That may not exist, so that is not an option.

I'm sure there must be a way to recode the patch so that it works with Bourne shell.

> 
> Also, just to clarify, should I make these simple code change in the source
> control?  I don't have a preference either way.  I don't know what is the
> right etiquette for contributing code changes.

Through Bugzilla.

Only committers can update the source code.
Comment 4 Sebb 2014-01-13 23:28:13 UTC
This seems to be a duplicate of Bug 21695. Looks like there is a solution in comment 1.

In any case, I don't think the jmeter.sh script should change directory internally.

If you really want to do that, just create a shell script that does so, rather than creating a soft link.
Comment 5 Sebb 2014-01-14 17:49:48 UTC

*** This bug has been marked as a duplicate of bug 21695 ***