Hide information during bash debug run
Disable debugging for the part with sensitive information and re-enable it afterwards.
if [[ $- =~ x ]]; then debug=1; set +x; fi
# your code with sensitive information
[[ $debug == 1 ]] && set -x
Hide output in Bash Script
If you want to redirect all output to /dev/null
within the script, that can be done like so (in this case, only performing the redirection if the environment variable DEBUG
is not set):
#!/bin/bash
[[ $DEBUG ]] || exec >/dev/null 2>&1
# ...continue with execution here.
You could also check for whether your input is from a TTY to detect interactive use:
if [ -t 0 ]; then
# being run by a human, be extra verbose
PS4=':$LINENO+'
set -x
else
# being run by a daemon, be outright silent
exec >/dev/null 2>&1
fi
See the bash-hackers page on the exec
builtin.
How to enable or disable multiple echo statements in bash ecript
The absolute easiest would be to insert the following line after the hashbang line:
echo() { :; }
When you want to re-enable, either delete the line or comment it out:
#echo() { :; }
If you're not using echo
but printf
, same strategy, i.e.:
printf() { :; }
If you absolutely need to actually echo/printf something, prepend the builtin
statement, e.g.:
builtin echo "This 'echo' will not be suppressed."
This means that you can do a conditional output, e.g.:
echo () {
[[ "$SOME_KIND_OF_FLAG" ]] && builtin echo $@
}
Set the SOME_KIND_OF_FLAG
variable to something non-null, and the overridden echo
function will behave like normal echo
.
EDIT: another alternative would be to use echo
for instrumenting (debugging), and printf
for the outputs (e.g., for piping purposes). That way, no need for any FLAG
. Just disable/enable the echo() { :; }
line according to whether you want to instrument or not, respectively.
Enable/Disable via CLI Parameter
Put these lines right after the hashbang line:
if [[ debug == "$1" ]]; then
INSTRUMENTING=yes # any non-null will do
shift
fi
echo () {
[[ "$INSTRUMENTING" ]] && builtin echo $@
}
Now, invoking the script like this: script.sh debug
will turn on instrumenting. And because there's the shift
command, you can still feed parameters. E.g.:
- Without instrumenting:
script.sh param1 param2
- With instrumenting:
script.sh debug param1 param2
The above can be simplified to:
if [[ debug != "$1" ]]; then
echo () { :; }
shift
fi
if you need the instrumenting flag (e.g. to record the output of a command to a temp file only if debugging), use an else
-block:
if [[ debug != "$1" ]]; then
echo () { :; }
shift
else
INSTRUMENTING=yes
fi
REMEMBER: in non-debug mode, all echo
commands are disabled; you have to either use builtin echo
or printf
. I recommend the latter.
Is there a way to hide/stop some output generated by debug
TL;DR;
Based on your exact example, this should be, your debug task:
- debug:
msg: "The system is now running Kernel Version {{ item.stdout }}"
loop: "{{ kernel.results }}"
when: item.changed
loop_control:
label: 'kernel'
Which will output
TASK [debug] *******************************************************************
ok: [local] => (item=kernel) => {
"msg": "The system is now running Kernel Version 4.14.35-1902.302.2.el7uek.x86_64"
}
You can't reduce it totally, as you want but you can indeed make loops less annoyingly verbose by defining a label
in the loop_control
attribute.
In this label
you can select one of the attributes of your dictionary to be displayed when Ansible loops over it rather than the full dictionary.
- debug:
msg: "The system is now running Kernel Version {{ item.stdout }}"
loop:
- some: foo
dict: foo
with: foo
an: foo
annoyingly: foo
long: foo
list: foo
of: foo
attributes: foo
name: bar
stdout: bar
loop_control:
label: "{{ item.name }}"
This will give a recap looking like this
TASK [debug] *******************************************************************
ok: [local] => (item=bar) => {
"msg": "The system is now running Kernel Version bar"
}
Versus the cluttered one without loop_control
:
TASK [debug] *******************************************************************
ok: [local] => (item={'some': 'foo', 'dict': 'foo', 'with': 'foo', 'an': 'foo', 'annoyingly': 'foo', 'long': 'foo', 'list': 'foo', 'of': 'foo', 'attributes': 'foo', 'name': 'bar', 'stdout': 'bar'}) => {
"msg": "The system is now running Kernel Version bar"
}
Also, in order to fix your warning, you just need to remove the Jinja curly bracers, as when
always assume you are going to pass a Jinja expression.
And testing that something == true
is an uneeded extra verbosity too, when: something-that-evaluates-to-true
is enough.
So you should use
when: item.changed
Instead of your actual
when: "{{ item.changed == true }}"
PS: since Ansible 2.5 loop
should be preferred rather than with_items
.
How do I suppress the console window when debugging python code in Python Tools for Visual Studio (PTVS)?
This was more difficult to figure out than expected, but as usual, simple once you know.
The quick answer.
In the Solution Explorer, right click on the project and select Properties. On the General tab check the box next to Windows Application.
Then save and close the properties window. Done!
Other details from the discussion of an issue posted in 2012 on the PTVS codeplex site.
Python shell appears in addition to output window of IDE
The typical way to hide the Python console window is to set the
Windows Application property (in the project properties window), which
will then run pythonw.exe instead of python.exe. This is only really
an option if you don't provide any input while your program is running
- the output window in VS is not a console and does not support typing into your program. Also, this option is per-project, so you'll have to
set it for each project. (It also seems to not be working in our
latest builds, so we'll fix that asap...)The other option is to stop printing output in Visual Studio and only
use the console window. If you are suffering performance issues, this
is more likely to solve the problem. To do this, open
Tools->Options->Python Tools->Advanced and deselect "Tee program
output to Debug Output window". You will probably also want to select
"Wait for input when process exits normally" while you are here. Now
all output will go to the Python console (you can right-click the
title bar and choose Properties to make it bigger), which will be
faster.
Hide the exported functions from appearing in the executable binary file
strip
The best way to achieve that is to use strip
. It will discard the symbols from the binary.
You have tons of options where the most aggressive one is to use -s
or --strip-all
which will remove all symbol and reloc information.
Usage: strip <option(s)> in-file(s)
Removes symbols and sections from files
The options are:
-I --input-target=<bfdname> Assume input file is in format <bfdname>
-O --output-target=<bfdname> Create an output file in format <bfdname>
-F --target=<bfdname> Set both input and output format to <bfdname>
-p --preserve-dates Copy modified/access timestamps to the output
-D --enable-deterministic-archives
Produce deterministic output when stripping archives (default)
-U --disable-deterministic-archives
Disable -D behavior
-R --remove-section=<name> Also remove section <name> from the output
-s --strip-all Remove all symbol and relocation information
-g -S -d --strip-debug Remove all debugging symbols & sections
--strip-dwo Remove all DWO sections
--strip-unneeded Remove all symbols not needed by relocations
--only-keep-debug Strip everything but the debug information
-N --strip-symbol=<name> Do not copy symbol <name>
-K --keep-symbol=<name> Do not strip symbol <name>
--keep-file-symbols Do not strip file symbol(s)
-w --wildcard Permit wildcard in symbol comparison
-x --discard-all Remove all non-global symbols
-X --discard-locals Remove any compiler-generated symbols
-v --verbose List all object files modified
-V --version Display this program's version number
-h --help Display this output
--info List object formats & architectures supported
-o <file> Place stripped output into <file>
GCC
In case you are compiling your binary with GCC, you can use gcc -s
to strip the symbol table.
Other compilers
Most of the compilers out there has the feature of stripping symbols and debug information from the binary. Check the manual of the compiler you are using.
How can I remove the debug banner in Flutter?
On your MaterialApp
set debugShowCheckedModeBanner
to false
.
MaterialApp(
debugShowCheckedModeBanner: false,
)
The debug banner will also automatically be removed on the release build.
Related Topics
Syscall Hooking on Kali Linux (Kernel Version 5)
The Button.Connect Syntax in Genie
How to Determine from Where a Program Jumped to an Invalid Address - Without Single-Stepping
Why a Static Library Can Depend on a Shared a Library
Killing Stanford Core Nlp Process
Eclipse Kura Installation on Raspberry Pi 3
Cuda - Confusion About The Visual Profiler Results of "Branch" and "Divergent Branch" (2)
Grep,How to Search for Exact Pattern
Passwd in One Command Isn't Working
Udev-How to Get Value of a Child Device Attributes
What's The Relation Between 32/64-Bit Application, Os and Processor
Using Sftp to Transfer Images from HTML Form to Remote Linux Server Using Perl/Cgi.Pm
Valueerror: Namespace Gtk Not Available
Logstash Too Many Files Opened
Copy Failed: Stat /Var/Lib/Docker/Tmp/Docker-Builder700869788/Private: No Such File or Directory