print values at fixed position in Terminal window using UNIX - shell

I am running a shell script which produces below output.
Built-By : apache
Created-By : Apache Maven
Implementation-Title : testApp
Implementation-Vendor-Id : com.test.app
Implementation-Version : testBox
Manifest-Version : 1.0
appname : TestStar
build-date : 02-03-2014-13 : 41
version : testBox
Expecting the below output: (Please ignore _ underscore)
Built-By_________________: apache
Created-By_______________: Apache Maven
Implementation-Title_____: testApp
Implementation-Vendor-Id_: com.test.app
Implementation-Version___: testBox
Manifest-Version_________: 1.0
appname__________________: TestStar
build-date_______________: 02-03-2014-13 : 41
version__________________: testBox
Someone Please help me. I am iterating two arrays to print these values.

show me your code.
maybe this would help:
#!/bin/bash
key=("appname" "version" "Created-By")
value=("TestStar" "testBox" "Apache Maven")
for i in "${!key[#]}";do
printf "%-15s %s\n" "${key[i]}" "${value[i]}"
done

Related

How to update message of dataflows in Nifi Registry?

In the progress of upgrading Nifi-1.10.0 from Nifi-1.9.2,'flow.xml.gz' is copied to new app.However,the files storaged in registry are unchanaged.
as following message:
$ cat 4.snapshot | grep 'version'
"version" : "1.9.2"
"version" : "1.9.2"
"version" : "1.9.2"
"version" : "1.9.2"
"version" : "1.9.2"
"version" : "1.9.2"
"version" : "1.9.2"
"version" : "1.9.2"
How to update them to show 'version:1.10.0'?there is a way to commit group in Nifi-1.10.0 but TOO TROUBLE!ANY OTHER SUGGESTION?Thank you!
The version fields in registry will get updated the next time you save a new version of those flows. It doesn't cause any issues for the versions to remain as 1.9.2, those flows can still be imported and used in 1.10.0.

How to check with svn if the trunk have just been tagged

I set up an automatic compilation process in shellscript, and I just want to figure if the trunk didn't received any commit from the last tagging... Is there a way to perform it with a simple svn command line, without read and compare the history, "scriptly" or manually ?
In SVN a tag is neither an alias for a revision nor immutable. Instead it is just a copy! It is possible to modify the tag after it has been created. So the only way is to compare the revision numbers of the two paths. This question shows how to get them.
Thanks to #ceving, here's a nice sample to check if a project tree is up-to-date regarding tags.
Given that a project is set as the following :
rootdev/prj1/
rootdev/prj1/trunk
rootdev/prj1/tags
Script :
#!/bin/bash
tabs 30 # be fancy
function last-rev ()
{
svn log "$1" -r HEAD:1 -l 1 -q | grep -ao '^r\S*'
}
find rootdev -ipath "*tags" |
while read tags
do
module="$(dirname $tags)"
modulename="$(basename $module)"
lasttag="$(ls -1 $tags | tail -n 1)"
lastrev=$(last-rev "$module")
lasttagrev=$(last-rev "$tags/$lasttag")
echo -ne "$modulename\t: $lasttag\t$lasttagrev/$lastrev "
[[ "$lastrev" == "$lasttagrev" ]] && echo "[UPTODATE]" || echo "[OUTDATED]"
done
Output :
DateUtils : 1.0.0 r116/r116 [UPTODATE]
ThisUtils : 1.0.0 r116/r116 [UPTODATE]
SomeUtils : 1.2.1 r125/r125 [UPTODATE]
ThatUtils : 1.0.1 r101/r101 [UPTODATE]
NotUtils : 1.0.0 r101/r128 [OUTDATED]
WhyUtils : 1.2.0 r130/r130 [UPTODATE]

MongoDB run query from terminal

I'm try run bash script from terminal (Ubuntu 14.04), but i'm get error:
$ ../scripts/for_webapp/init_devices_limit.sh
db.company.update({"_id": NumberInt(777)}, {$set: {"devices_limit": NumberInt(-1)}}, {"multi":true});
MongoDB shell version: 3.2.5
connecting to: localhost:27017/statistic
2016-04-22T12:37:01.366+0500 E QUERY [thread1] SyntaxError: expected expression, got end of script #(shell eval):1:25
Script:
#!/usr/bin/env bash
: ${DBHOST:=localhost}
: ${DBPORT:=27017}
: ${DBNAME:=statistic}
: ${COMPANY_ID:=777}
: ${INIT_VALUE:=-1}
QUERY='db.company.update({"_id": NumberInt('$COMPANY_ID')}, {$set: {"devices_limit": NumberInt('$INIT_VALUE')}}, {"multi":true});'
echo $QUERY
mongo $DBHOST:$DBPORT/$DBNAME --eval $QUERY
I'm solve this with using EOF input signal (without use --eval argument).
#!/usr/bin/env bash
: ${DBHOST:=localhost}
: ${DBPORT:=27017}
: ${DBNAME:=statistic}
: ${COMPANY_ID:=777}
: ${INIT_VALUE:=-1}
QUERY='db.company.update({"_id": NumberInt('$COMPANY_ID')}, {$set: {"devices_limit": NumberInt('$INIT_VALUE')}})'
echo $QUERY
# mongo $DBHOST:$DBPORT/$DBNAME --eval $QUERY
# don't use --eval
mongo $DBHOST:$DBPORT/$DBNAME <<_EOF_
$QUERY
_EOF_

sh file to construct mongo document

My document structure looks like this:
{"name":"John", "age":32, ...other fields}
All other fields need not be initialized, only name and age. I want to make a script that takes in name and number
./client.sh John 32
and in the script, it will do something like
db.client.insert({"name":$1,"age":$2});
how to achieve this?
Here is a simple example script that works
#!/bin/bash
if [ $# -lt 2 ]
then
echo "USAGE: $0 name age"
exit 1
fi
mongo <<EOF
use test
db.client.insert({"name":"$1", "age":$2})
db.client.find()
EOF
It assumes that mongo is installed and in your path and that you have the client collection in the test database.
A sample run below
hduser#localhost:~/temp$ ./mongo_ins.sh "overflow" 20
MongoDB shell version: 2.6.10
connecting to: test
switched to db test
WriteResult({ "nInserted" : 1 })
{ "_id" : ObjectId("56b35d134c24bf7c1190cfb3"), "name" : "Stack", "age" : 1 }
{ "_id" : ObjectId("56b35dabe23223802ea3fa61"), "name" : { }, "age" : 10 }
{ "_id" : ObjectId("56b35ebbd69a0abeeb817fe3"), "name" : "overflow", "age" : 20 }
bye
Hope this helps

Wildfly Maven plugin + hot deployment

I have a Java Spring application, configured in Eclipse Mars and I am running Wildfly 9 from with in Eclipse. I am using the wildfly-maven-plugin to deploy to server.
These are the steps I follow:
Start the server from eclipse and do Maven build which also deploys the application to server. I can see whole lot of logs on server of "successful deployment"and I can access my application in browser. It creates a folder under "/standalone/data/content" but no war or exploded WAR under "standalone/deployments"
If I change some code and save it in eclipse, (I have checked Automatically publish check box and build on save), The sever logs says: Replaced deployment "myApp.war" with deployment "myApp.war" Content removed from location "standalone\data\content..."
And I see the prev folder created during step 1 is removed and myApp.war is added to deployment folder. But now I can not access my application in browser.
auto-deploy-exploded="true"
That is in the section of standalone.xml.
The wildfly-maven-plugin deploys applications using management operations. It doesn't deploy any exploded content only the archive. In other words you'd need to recreate the deployment archive before you redeploy otherwise changes won't be seen.
As #ozOli says it's probably best to use JBoss Tools.
There is an open issue to allow exploded content to be deployed. This is currently suggested only for the run goal, but it could likely be expanded to deploy exploded content as well. I think deploying exploded content works.
In general though the issue with "hot deployments" is source needs to be recompiled and then redeployed. The redploy is key as annotations and such need to be rescanned.
For Eclipse you can use the JBoss Tools plugins: http://tools.jboss.org/
Wildfly has administrative REST support. No need for fancy tools.
Here is a BASH script for Wildfly and Glassfish auto-redeploy of Maven projects, ie. when working with auto-compile in Eclipse:
set -x
pubname=$1
usewar=$2
if [[ -z $pubname ]]; then
pubname=ROOT
fi
if [[ -z "$usewar" ]]; then
usewar=0
else
usewar=1
fi
if ! webappdir=$(ls -d `pwd`/target/*-SNAPSHOT); then
webappdir=$(pwd)
fi
iswildfly=0
ctxroot="/$pubname"
if [[ "$pubname" == "ROOT" ]]; then
ctxroot="/"
fi
port=4848
if curl http://localhost:9991/ ; then
port=9991
iswildfly=1
elif curl http://localhost:9990/ ; then
port=9990
iswildfly=1
fi
if (( usewar )); then
webappdir=$webappdir.war
if ! (( iswildfly )); then
webappdir="#"$webappdir
fi
fi
wildflycmd() {
local cmd=$1
curl --retry 100 --retry-delay 3 --retry-connrefused --digest -L -u admin:admin -D - http://localhost:$port/management \
--header "Content-Type: application/json" \
-d "$cmd"
}
if (( iswildfly )); then
wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "undeploy", "address" : {"deployment" : "'$pubname'.war"}},{"operation" : "remove", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
if (( usewar )); then
wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "add", "address" : {"deployment" : "'$pubname'.war"}, "content" : [{"url" : "file:'$webappdir'"}]},{"operation" : "deploy", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
else
wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "add", "address" : {"deployment" : "'$pubname'.war"}, "content" : [{"path" : "'$webappdir'", "archive":"false"}]},{"operation" : "deploy", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
fi
fi
inotifyEvents=""
if ! [[ "$(uname)" =~ ^CYGWIN ]]; then
inotifyEvents="-e close_write"
fi
while inotifywait $inotifyEvents -r $webappdir --excludei "\.(js|html|css)$" || :; do
if ! (( iswildfly )); then
curl -v -H 'Accept: application/json' \
-X POST \
-H 'X-Requested-By: loadr' \
-F force=true \
-F id=$webappdir \
-F isredeploy=true \
-F virtualservers=server \
-F contextRoot=$ctxroot \
-F name=$pubname \
http://localhost:$port/management/domain/applications/application
else
wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "redeploy", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
fi
done
Just start the Wildfly instance with mvn clean wildfly:run.
Source: https://github.com/jjYBdx4IL/snippets/blob/master/java/jee_autodeploy.sh

Resources