More Elegant "Ps Aux | Grep -V Grep"

How to avoid multiple OR statement bash

Generally, no, unless the effects of each flag are independent. You could try building up the arguments to grep in an array. For example:

grep_options=()
if [ $w == TRUE ]; then
grep_options+=( -w )
fi

if [[ $s == TRUE ]]; then
grep_options+=(-s)
fi

# etc.

grep "${grep_options[@]}" search_pattern INFILE

using Grep or Sed to get a text beetween {}

Didn't realize that OP has { and } in two separate lines. sed would be easier,

 $ sed -n '/{/,/}/{//!p}' inputfile

For square brackets, you have to escape the characters:

 $ sed -n '/\[/,/\]/{//!p}' inputfile

inputfile:

$ cat inputfile
Some text inside
{
between braces
}
some other text

[
between square bracket
]

some more text

output:

$ sed -n '/{/,/}/{//!p}' inputfile
between braces

$ sed -n '/\[/,/\]/{//!p}' inputfile
between square bracket

If they are on the same line, use perl-style-regex in grep and option -o:

 $ echo 'Some text {between}'  | grep -o -P '(?<=\{).*(?=\})' 
between

$ echo 'Some text [between]' | grep -o -P '(?<=\[).*(?=\])'
between

Is there elegant way to terminate running instance of spring boot stand alone application?

You can shutdown spring boot application by enabling actuator shutdown end point /actuator/shutdown, first we need to enable it here

management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true

And then invoke it

localhost:port/actuator/shutdown

How to figure out what is running on my (NVIDIA) GPU?

See all processes being run by the user who used the GPU. Kill all processes that may have used the GPU.

ps -ef | grep <username>

You could also try

sudo nvidia-smi --gpu-reset

If nothing works then consider rebooting.

Regarding PID Shell Script

You may background testarg.sh, which puts its pid into $!, and then wait for it:

#! /bin/bash
...

$CUSTBIN/testarg.sh &

LOGFILE=testarg.$(date +%d%b%y).$!.log # testarg.09Jun10.12345.log

wait $!

# ... $? is set as you expect ...

[ -f $LOGFILE ] && grep {pattern} $LOGFILE

...


Related Topics



Leave a reply



Submit