Why are strings generated by gsha256sum 512 bits long? - gnu-coreutils

On MacOS with brew install coreutils, when executing:
$ SEED="I am a seed"
$ SECRET=$(echo -n $SEED|gsha256sum | cut -d\ -f1)
4beb564ded9dd12eb8de15d5543294eba13463044808e877289dc6df9a521cda
echo -n $SECRET | wc -m
64
Trying to generate a 512bit seed, which is the actual result, but I would assume that gsha256sum returned a 256bit string, not a 512bit string.

Related

awk command not working with kubectl exec

From outside container:
$ kubectl exec -it ui-gateway-0 -- bash -c "ps -ef | grep entities_api_svc | head -1"
root 14 9 0 10:34 ? 00:00:02 /svc/bin/entities_api_svc
$ kubectl exec -it ui-gateway-0 -- bash -c "ps -ef | grep entities_api_svc | head -1 | awk '{print $2}'"
root 14 9 0 10:34 ? 00:00:02 /svc/bin/entities_api_svc
From inside container:
[root#ui-gateway-0 /]# ps -ef | grep entities_api_svc | head -1 | awk '{print $2}'
14
I find it easier to use single quotes on the sh/bash command argument so it is closer to what you would type in the shell:
kubectl exec -it ui-gateway-0 -- \
bash -c 'ps -ef | grep entities_api_svc | head -1 | awk "{print \$2}"'
This means the awk uses double quotes, which requires the shell variable marker $ to be escaped.
In the original command, the shell running kubectl was replacing $2 with a zero length string so awk would see only print, which prints the whole line
Multiple levels of nesting
Nested shell escaping gets very obscure very quickly and hard to debug:
$ printf '%q\n' 'echo "single nested $var" | awk "print $2"'
echo\ \"single\ nested\ \$var\"\ \|\ awk\ \"print\ \$2\"
$ printf '%q\n' "$(printf '%q\n' 'echo "double nested $var" | awk "print $2"')"
echo\\\ \\\"double\\\ nested\\\ \\\$var\\\"\\\ \\\|\\\ awk\\\ \\\"print\\\ \\\$2\\\"
If you add a file grep-entities.sh in container
#!/bin/bash
set -uex -o pipefail
ps -ef | grep entities_api_svc | head -1 | awk '{print $2}'
You then don't need to worry about escaping
pid=$(sshpass -p "password" ssh vm#10.10.0.1 kubectl exec ui-gateway-0 -- /grep-entities.sh)
Also pgrep does the scripts job for you
kubectl exec ui-gateway-0 -- pgrep entities_api_svc

How can I use Tensorflow in tizen studio?

I want to use tensorflow in tizen.
Tizen studio's architecture is x86.
But tensorflow is only 64-bit.
How can I use tensorflow in tizen studio??
Download packages for target device
tensorflow
python
db4
mkdir tmp
cd tmp
BASE_URL='http://download.tizen.org/snapshots/tizen/5.0-base/latest/repos/standard/packages/armv7l/'
wget -O - $BASE_URL 2>/dev/null | egrep 'db4-[0-9]' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
wget -O - $BASE_URL 2>/dev/null | egrep 'python-[0-9]' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
UNIFIED_URL='http://download.tizen.org/snapshots/tizen/5.0-unified/latest/repos/standard/packages/armv7l/'
wget -O - $UNIFIED_URL 2>/dev/null | grep 'tensorflow-v' | awk -F'"' '{print $2}' | xargs -i wget $UNIFIED_URL{}
Install packages on target device
sdb root on; sdb shell 'mount -o remount,rw /'
sdb push *.rpm /tmp
sdb shell 'cd /tmp; rpm -ivh --force db4*.rpm; rpm -ivh --force *python*.rpm; rpm -ivh --force tensorflow*.rpm'
cd ..
rm -r tmp
Download packages needed for building
tensorflow
tensorflow-devel
libpython-2.7
libgfortran
libgomp
mkdir tmp
cd tmp
BASE_URL='http://download.tizen.org/snapshots/tizen/5.0-base/latest/repos/standard/packages/armv7l/'
wget -O - $BASE_URL 2>/dev/null | grep 'libpython-2.7' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
wget -O - $BASE_URL 2>/dev/null | grep 'libgfortran-' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
wget -O - $BASE_URL 2>/dev/null | grep 'libgomp-' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
UNIFIED_URL='http://download.tizen.org/snapshots/tizen/5.0-unified/latest/repos/standard/packages/armv7l/'
wget -O - $UNIFIED_URL 2>/dev/null | grep 'tensorflow' | grep -v 'lite' | awk -F'"' '{print $2}' | xargs -i wget $UNIFIED_URL{}
Extract header and so files and selectively import to project lib folder
ls *.rpm | xargs -i bash -c "rpm2cpio {} | cpio -idmv"
cd usr/lib/
ln -s libpython2.7.so.1.0 libpython2.7.so
ln -s libgfortran.so.3 libgfortran.so
cp libgfortran.so* libgomp.so.1* libpython2.7.so* libpywrap_tensorflow_internal.so ../../../lib/
cd ../include
cp -r tensorflow ../../../inc/
cd ../../..
rm -r tmp
Set up include path in Tizen Studio project
screenshot
Set up library path and add libraries to Tizen Studio project
screenshot
Note that if you want to build the project for emulator, you have to use library files for x86 architecture, so you would have to replace "armv7l" in all the URLs above with "i686"
Tizen studio is just development tool.
Tizen supports x86-64(AMD64) and you can use the tensorflow on Tizen.
If you want to use Tizen with tensorflow, you need to install some packages(tensorflow, python,...) yourself.
If you can afford using Tensorflow-Lite, you can use it directly in Tizen-latest. Soon, with Tizen 5.5 M2, there will be Machine Learning APIs that allows app developers to directly plugin .tflite models as well as their own native models (as .so files or as functions) without worrying about importing external libraries.
Anyway, if you want to do it right now, use the Tizen-latest (Tizen:Unified project in build.tizen.org), use tensorflow-lite-dev.rpm package directly or use nnstreamer-capi package, which gives you some easy-to-use interfaces. Note that nnstreamer (https://github.com/nnsuite/nnstreamer ) is going to be the main engine for Tizen-Machine-Learning (backend of its Machine Learning API sets). Although nnstreamer is compatible with Tensorflow (non-lite), Caffe2, PyTorch, ROS, and so on, they are not included in Tizen by default.

grep pattern match with line number

I want to get the line number of the matched pattern but I have a condition that the pattern match should have 'digits' .
If I use
grep -ri -n "package $i " . | grep -P '\d'
then I would get the line number of the lines matching pattern but also I would get the lines with 'package ' without any digits:
Below output shows me line number 71 for 'package ca-certificates' but there are four more lines for gluterfs that I dont need . I dont need those lines as they dont have any digit in them .
for i in $(awk '{print $1}' ~/Version-pkgs)
do
grep -ri -n "package $i " . | grep -P '\d'
done
sh search-version-pkgs.sh
./core.pkglist:71:package ca-certificates 2017.2.14 65.0.1.el6_9 arch noarch
./dev.pkglist:1343:package glusterfs-devel \
./dev.pkglist:1346:package glusterfs-api-devel \
./dev.pkglist:1346:package glusterfs-api-devel \
./dev.pkglist:1346:package glusterfs-api-devel \
./dev.pkglist:1343:package glusterfs-devel \
./core.pkglist:234:package initscripts 9.03.58 1.0.3.el6_9.2prerel7.6.0.0.0_88.51.0 arch ${bestArch}
./core.pkglist:397:package nspr 4.13.1 1.el6
./dev.pkglist:859:package nspr-devel \
./dev.pkglist:859:package nspr-devel \
./core.pkglist:401:package nss 3.28.4 4.0.1.el6_9 arch ${bestArch}
Running below script gives me exact pattern match i.e. 'package ' but I would not get the line number of them
for i in $(awk '{print $1}' ~/Version-pkgs)
do
egrep -ri "package $i " . | grep -P '\d'
done
sh search-version-pkgs.sh
./core.pkglist:package ca-certificates 2017.2.14 65.0.1.el6_9 arch noarch
./core.pkglist:package initscripts 9.03.58 1.0.3.el6_9.2prerel7.6.0.0.0_88.51.0 arch ${bestArch}
./core.pkglist:package nspr 4.13.1 1.el6
./core.pkglist:package nss 3.28.4 4.0.1.el6_9 arch ${bestArch}
./core.pkglist:package nss-util 3.28.4 1.el6_9 arch ${bestArch}
./core.pkglist:package tzdata 2018e 3.el6 arch noarch
How can get the output with the line number along with the pattern match as file:lineno.:package pkgname digits
for i in $(cut -f1 ~/Version-pkgs)
do
grep -rin "package $i.*[0-9]" .
done
no need to use grep twice
Oneliner :
grep -rinf <(sed -E 's,([^ ]*).*,package \1.*[0-9],' ~/Version-pkgs) .

Comparing version strings in Zsh

I am using this script:
if [[ -f /usr/bin/atom ]]; then
ATOM_INSTALLED_VERSION=$(rpm -qi atom | grep "Version" | cut -d ':' -f 2 | cut -d ' ' -f 2)
else
ATOM_INSTALLED_VERSION=""
fi
ATOM_LATEST_VERSION=$(wget -q "https://api.github.com/repos/atom/atom/releases/latest" -O - | grep -E "https.*atom-amd64.tar.gz" | cut -d '"' -f 4 | cut -d '/' -f 8 | sed 's/v//g')
if [[ "$ATOM_INSTALLED_VERSION" -lt "$ATOM_LATEST_VERSION" ]]; then
sudo dnf install -y https://github.com/atom/atom/releases/download/v${ATOM_LATEST_VERSION}/atom.x86_64.rpm
fi
to check for Atom upgrades and install them if available. The problem is that the test:
[[ "$ATOM_INSTALLED_VERSION" -lt "$ATOM_LATEST_VERSION" ]]
returns:
zsh: bad floating point constant
where (showing input and output):
$ printf $ATOM_INSTALLED_VERSION
1.8.0%
$ printf $ATOM_LATEST_VERSION
1.12.7%
how do I write a test that will work? I have tried using (( $ATOM_INSTALLED_VERSION < $ATOM_LATEST_VERSION )) but that also failed giving:
zsh: bad floating point constant
zsh comes equipped with a function for version string comparisons, see zshcontrib(1).
installed=$(rpm -q --qf '%{VERSION}' atom)
latest=$(wget -q ...)
autoload is-at-least
is-at-least $latest ${installed:-0} || sudo dnf install -y ...

tput: unknown terminal

I'm on AIX-6.1 and I'm trying to make use of tput inside my $PS1.
I've confirmed I can't even run tput from the commandline. Following is my session:
# tput
unknown terminal "xterm"
# echo $TERM
xterm
# tput -T ansi
unknown terminal "ansi"
In fact, ...
# ls /usr/lib/terminfo/x
x1700 xl83 xterm+pcc3 xterm+pcfkeys xterm-88color xterm-hp xterm-old xterm-vi
x1720 xtalk xterm+pcf0 xterm+pcfn xterm-8bit xterm-ic xterm-r5 xterm-vt220
x1750 xterm xterm+pcf1 xterm-16color xterm-basic xterm-mono xterm-r6 xterm-vt52
x820 xterm+pcc0 xterm+pcf2 xterm-24 xterm-bold xterm-new xterm-rep xterm-xfree86
xdku xterm+pcc1 xterm+pcf3 xterm-256color xterm-boldso xterm-noapp xterm-sco xterm-xmc
xitex xterm+pcc2 xterm+pcfN xterm-65 xterm-color xterm-nrc xterm-sun xterms
# ls /usr/lib/terminfo/x | wc -l
48
# for term in $(ls /usr/lib/terminfo/x) ; do tput -T $term ; done 2>&1 | grep 'unknown terminal' | wc -l
48
# for term in $(ls /usr/lib/terminfo/x) ; do TERM=$term tput ; done 2>&1 | grep 'unknown terminal' | wc -l
48
Any ideas? Thanks in advance.
Is your TERMINFO variable set? Without it, I believe the system won't find your terminfo files. Or perhaps it is set incorrectly?
If you're running sh, ksh, bash or similar, try:
export TERMINFO=/usr/lib/terminfo
If you're not sure what shell you're using (I'm pretty sure you do, but others might read this too), type:
echo $SHELL
If you're using csh, tcsh or similar, then you should instead type:
setenv TERMINFO /usr/lib/terminfo
After that, try running tput again.
I fixed this in Mac OS Catalina with,
export TERMINFO=/usr/share/terminfo