Having issues running the result of an Xargs find to get version of found items - find

I'm able to return the path to the java executable but what i really want is the version of java so want to run the path returned with -version attached to the end.
Any help appreciated.
locate -b '\java' | xargs -ri find {} -prune -type f -executable
Thanks

Here was the eventual answer.
locate -b '\java' | xargs -ri find {} -prune -type f -executable | xargs bash -c '$0 -version'
java version "1.6.0_41"
OpenJDK Runtime Environment (IcedTea6 1.13.13) (rhel-1.13.13.1.el6_8-x86_64)
OpenJDK 64-Bit Server VM (build 23.41-b41, mixed mode)```

Related

Apache Kafka 2.12-1.1.0 not working with JDK -10.0.1

Why doesn't Apache Kafka 2.12-1.1.0 work with JDK 10.0.1?
./bin/zookeeper-server-start.sh config/zookeeper.properties
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
/..../kafka_2.12-1.1.0/bin/kafka-run-class.sh: line 252: [[: 10 2018-04-17: syntax error in expression (error token is "2018-04-17")
[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/..../kafka_2.12-1.1.0/bin/../logs/zookeeper-gc.log instead.
Unrecognized VM option 'PrintGCDateStamps'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Changing the bin/kafka-run-class.sh with below code did the magic:
In Line #251
Before:
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*"/\1/p')
After:
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*/\1/p')
You can remove the offending logging option KAFKA_GC_LOG_OPTS for java 10 from the file kafka-run-class.sh
from
KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
to
KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails"
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version
"([0-9]).$/\1/p')
This line solved my problem with openjdk!
This is the original line from bin/kafka-run-class.sh that you need replace:
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version
"([^.-])."/\1/p')
There is a problem in the regex used for identifying the java version in the bin/kafka-run-class.sh especially if you are using openjdk.
You can replace line 255 in the bin/kafka-run-class.sh with :
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
as in https://github.com/apache/kafka/blob/trunk/bin/kafka-run-class.sh#L286
Above all answers are from the shell script point of view. If some people are using a bat file on the windows machine below answer will be helpful.
Windows Bat file
Go to ..\kafka_2.12-2.2.0\bin\windows and search for kafka-run-class.bat file
Go to Line Number 158 and set the JDK Path.
IF ["%JAVA_HOME%"] EQU [""] (
set JAVA=java
) ELSE (
set JAVA="..\Java\jdk12\bin\java"
)
Shell Script
Go to ..\kafka_2.12-2.2.0\bin\ and search for kafka-run-class.sh file.
and then search for $JAVA_HOME and go this line update your JDK path accordingly.
if [ -z "$JAVA_HOME" ]; then
JAVA="java"
else
JAVA="$JAVA_HOME\java"
fi
JAVA = "../Java/jdk12/bin/java"
echo $JAVA
I think this will address the issue. This will occur when we have multiple JDK installed on our machine and want to test the things.
I removed the tags like PrintGCDateStamps,UseGCLogFileRotation from line 314

Universal ctags with emacs

Sorry I am trying to configure ctags with emacs but I am in trouble.
I compiled global with this configure:
./configure --with-universal-ctags=/usr/local/bin/ctags
and I executed make && make install.
Then I changed the default target in the file .globalrc from native to new-ctags.
Finally I executed ggtags-create-tags within emacs.
Unfortunately I got the error
‘gtags’ non-zero exit: gtags: execvp failed.
gtags: unexpected EOF.
Can anyone help me, thanks
Using universal ctags is as simple as:
Run over a project (-R is to walk the project recursively, and -e is to use Emacs-compatible syntax):
$ ctags -eR
Alternatively if you like to only include files with certain extensions, you can use -a (append, creates a file if doesn't exist) option with find utility, like:
$ find -name "*.cpp" -print -or -name "*.h" -print -or -name "*.hxx" -print -or -name "*.cxx" -print | xargs ctags -ea
Run M-x visit-tags-table in Emacs, and navigate to the created TAGS file.

Determine if app is Wayland or X client

Is there a way to determine if an arbitrary app is an X client or a Wayland client (or neither) from the command line without fully launching it?
You can run ldd on the binary to check which libraries it links against. If it has "libwayland-client" you're probably looking at a Wayland client. For X you need to look for "libX11" or "libxcb".
To expand on the excellent answer given by #Alexander Sukhoverkhov what needs to be done is:
cd /usr/bin
ldd $application_name | grep wayland
Furthermore, to check which binaries have wayland support you could try:
cd /usr/bin
find . | xargs ldd | grep wayland -B 55
The above is not really very clean but it works. You can further pipe it to a file and then use vim to navigate.
cd /usr/bin
find . | xargs ldd | grep wayland -B 55 >> candidates
vim candidates
# Use vi movement
The -B flag stands for before and helps to print the binary name.

Find and soft link without the parent path

So I have a find command as below which finds the libclntsh.so.* files in a directory instantclient.
find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*"
This results in for e.g.,
instantclient/libclntsh.so.11.1
How do I now ln within instantclient directory, ln -s libclntsh.so.11.1 libclntsh.so all with a find command in combination with exec
I should mention here that I DO NOT want to cd into instantclient.
And this is for Alpine Linux.
Use the -execdir option. As per manual:
-execdir command {} ;
Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files.
So your command will be:
find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*" -execdir ln -s {} libclntsh.so \;
EDIT:
Another solution
find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*" | xargs -I {} sh -c 'ln -s $(basename {}) instantclient/libclntsh.so'

alternative to 'rename' command in CentOS 5.9

I need to rename all files whose name contains the substring 200at and substitute it with 200_at.
In Ubuntu, I would do:
find . -type f -name '*200at*' -exec rename -n 's/200at/200_at/' {} \;
In CentOS (version 5.9) it doesn't work. The command rename doesn't seem to support perl expressions and the above command does nothing at all.
Any ideas for an alternative?
In my experience with CentOS, we always used the mv (move) command for renaming things. ie:
mv 200at ./200_at
hope that works as your alternative.