parsing command line output on Windows command line batch file - windows

I have this command that scan a file and returns a summary.
For example on running this command
omsCmdLineUtil.exe process C:\test.exe Default
the result output is:
Ticket:[ 2214271306 ]
Process Details
---------------
File: [ C:\test.exe ]
MD5: [ D41D8CD98F00B204E9800998ECF8427E ]
SHA1: [ DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 ]
SHA256: [ E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 ]
File Size: [ 0 bytes ]
File Type Category: [ O ]
File Type: [ - ]
File Type Description: [ empty ]
[ Clean ] Ahnlab scan engine [ 1 ms ]
[ Clean ] ClamAV scan engine [ 1 ms ]
[ Clean ] BitDefender scan engine [ 1 ms ]
[ Clean ] Avira scan engine [ 1 ms ]
[ Clean ] Quick Heal scan engine [ 1 ms ]
[ Clean ] ThreatTrack scan engine [ 1 ms ]
[ Clean ] ESET scan engine [ 1 ms ]
[ Clean ] Total Defense scan engine [ 1 ms ]
Scan Completion
---------------
[ Clean ]
Ticket: [ 2214271306 ]
File path: C:\test.exe
Scan time: 1 ms [12/20/2015 13:00:06:791]
Process Completion
------------------
Ticket: [ 2214271306 ]
User agent: Default
Profile: Default
Result: [ Allowed ]
File processed: C:\test.exe
I want to create a batch file that parses this result by searching for the output line Result:, check if it's [ Allowed ] or [ Blocked ] and return 0 for allowed and 1 for blocked.
I tried something like this, but its not really working:
omsCmdLineUtil.exe process C:\test.exe Default | set ts = findstr /C:"Result: [ Allowed ]"
if %ts% == "Result: [ Allowed ]" return 0
else return 1
Which modification on code is necessary to get the expected result?

there is no return in Batch. I think, you want exit /b <errorlevel>
omsCmdLineUtil.exe process C:\test.exe Default | find "Result: [ Allowed ]" >nul && Exit /b 0 || Exit /b 1
Instead of Exit 0 you can of Course also use set ts=0 and use that. Or use echo instead.
Some explanations:
>nul redirects the output to nirvana, keeping your screen clean.
&& acts as "If previous command was successfull, then..." (string was found)
|| acts as "if previous command was not successfull, then...` (string was not found)
I prefer using find when possible because of it's simpler syntax, but of course findstr /C:"Result: [ Allowed ]"will also work

Related

Perf on MIPS debug kernel, unable to enable frame_pointer

I am trying to use perf tool for MIPS & facing some trouble in getting back-stacks.
How can I enable FRAME_POINTER for mips ? I have DEBUG_KERNEL enabled, but it looks like -fno-omit-frame-pointer is not applicable for MIPS arch in kernel.
Does it mean frame pointer based stack unwinding with perf can't be achieved for MIPS ?
I don't see mips toolchain complaining about -fno-omit-frame-pointer flag
EDIT1
I am able to record perf events. Sample output for perf report
Report wouldn't help much without the stack unwinding.
# ./perf --version
perf version 5.6.rc2.gd04712cd3bd7
# uname -a
Linux localhost 3.14.28-1.19 #1 SMP Mon Feb 17 16:48:44 IST 2020 mips GNU/Linux
EDIT2
Perf features detected
Auto-detecting system features:
... dwarf: [ on ]
... dwarf_getlocations: [ on ]
... glibc: [ on ]
... gtk2: [ OFF ]
... libaudit: [ on ]
... libbfd: [ OFF ]
... libcap: [ OFF ]
... libelf: [ on ]
... libnuma: [ OFF ]
... numa_num_possible_cpus: [ OFF ]
... libperl: [ OFF ]
... libpython: [ OFF ]
... libcrypto: [ OFF ]
... libunwind: [ OFF ]
... libdw-dwarf-unwind: [ on ]
... zlib: [ on ]
... lzma: [ on ]
... get_cpuid: [ OFF ]
... bpf: [ OFF ]
... libaio: [ on ]
... libzstd: [ OFF ]
... disassembler-four-args: [ OFF ]
EDIT3
I see feature test for libunwind had failed
cat linux-5.6-rc2/tools/build/feature/test-libunwind.make.output
/tmp/ccQnV5jZ.o: In function `main':
test-libunwind.c:(.text+0x1c): undefined reference to `_Umips_create_addr_space'
test-libunwind.c:(.text+0x4c): undefined reference to `_Umips_init_remote'
test-libunwind.c:(.text+0x70): undefined reference to `_Umips_dwarf_search_unwind_table'
collect2: error: ld returned 1 exit status
If I see the makefile for feature tests libunwind linking is not done for MIPS.
EDIT4
Usual workflow
perf record -F 99 -ag -e cycles:u -- sleep 5
perf report
Attempt to use dwarf
# perf record -F 99 -ag --call-graph=dwarf -- sleep 10
Error:
The sys_perf_event_open() syscall returned with 89 (Function not implemented) for event (cycles).
/bin/dmesg | grep -i perf may provide additional information.
dmesg is empty

Keep files one daily, one 3 days and one week and delete others

I have a folder containing database backup files for the last 15 days.
I need to delete all files and keep only one daily, one 3 days and one week.
Can someone help on this ?
I tried some scripts but none met my requirements
mkdir -p monthly
mkdir -p weekly
ln backup_$NOW.tgz weekly/
# find current month
month=$(date +%Y-%m-)
# find the first file of the current month in the weekly folder
first_monthly=$(ls --sort=time -1 weekly/*$month* 2>/dev/null | tail -1)
# and put it in the monthly folder
ln -f $first_monthly monthly/
# we need only 5 weekly backups
ls --sort=time -1 weekly/* 2>/dev/null | tail -n+6 >> /tmp/deletebackups.txt
# we need only 5 monthly backups
ls --sort=time -1 monthly/* 2>/dev/null | tail -n+6 >> /tmp/deletebackups.txt
# delete the extra files
#rm $(cat /tmp/deletebackups.txt) 2>/dev/null
xargs --arg-file /tmp/deletebackups.txt rm
here's one way to determine what to keep or delete. it uses an array of "age in days to keep" and then checks to see if the file age is in that collection.
$DaysOldToKeep = #(
0
3
7
)
$SourceDir = $env:TEMP
$Today = (Get-Date).Date
$FileList = Get-ChildItem -LiteralPath $SourceDir -File |
Sort-Object -Property CreationTime
foreach ($FL_Item in $FileList)
{
$DaysOld = ($Today - $FL_Item.CreationTime).Days
if ($DaysOld -notin $DaysOldToKeep)
{
Write-Warning ('[ {0} ] is [ {1} ] days old & should be removed.' -f $FL_Item.Name, $DaysOld)
}
else
{
Write-Host (' [ {0} ] is [ {1} ] days old & should be KEPT.' -f $FL_Item.Name, $DaysOld)
}
}
truncated output ...
WARNING: [ testing-making-dir-and-file.txt ] is [ 9 ] days old & should be removed.
WARNING: [ hd4B753.tmp ] is [ 8 ] days old & should be removed.
[ Itunes_AlbumAutoRating_Disable.ps1_2019-04-08.log ] is [ 7 ] days old & should be KEPT.
[ vscode-inno-updater-1554768842.log ] is [ 7 ] days old & should be KEPT.
[ hd464FA.tmp ] is [ 7 ] days old & should be KEPT.
[ hd4E2F0.tmp ] is [ 7 ] days old & should be KEPT.
WARNING: [ Genre-List_2019-04-09.log ] is [ 6 ] days old & should be removed.
WARNING: [ Grouping-Strings-List_2019-04-10.log ] is [ 5 ] days old & should be removed.
WARNING: [ Itunes_R-PC-SC_Save.ps1_2019-04-11.log ] is [ 4 ] days old & should be removed.
[ Magenoob_-_Merged_User_Info.csv ] is [ 3 ] days old & should be KEPT.
[ Itunes_Default-Rating_Set.ps1_2019-04-12.log ] is [ 3 ] days old & should be KEPT.
[ MagicTheGathering_-_Scryfall-Default-Cards.json ] is [ 3 ] days old & should be KEPT.
WARNING: [ hd4C490.tmp ] is [ 2 ] days old & should be removed.
WARNING: [ hd45A92.tmp ] is [ 1 ] days old & should be removed.
[ exthost-825471.cpuprofile ] is [ 0 ] days old & should be KEPT.
[ vscode-inno-updater-1555314279.log ] is [ 0 ] days old & should be KEPT.
[ npp.7.6.6.Installer.x64.exe ] is [ 0 ] days old & should be KEPT.
[ hd43E2A.tmp ] is [ 0 ] days old & should be KEPT.
[ hd44D37.tmp ] is [ 0 ] days old & should be KEPT.
[ hd4488C.tmp ] is [ 0 ] days old & should be KEPT.
[ hd45A09.tmp ] is [ 0 ] days old & should be KEPT.
[ Itunes_AlbumAutoRating_Disable.ps1_2019-04-15.log ] is [ 0 ] days old & should be KEPT.
A way to retrieve the first newest files would be :
ls -t weekly/ | head -1
And to have the rest of the oldest, to delete :
ls -t weekly/ | tail +2
If you want to keep it bash only, it may be the simplest way.
try something like this (remove -whatif if you want really remove):
$File1Founded=$false
$File3Founded=$false
$File7Founded=$false
$CurrentDate1=(get-date).Date
$CurrentDate3=(get-date).AddDays(-3).Date
$CurrentDate7=(get-date).AddDays(-7).Date
Get-ChildItem "C:\temp\test1" -file | sort CreationTime -Descending | %{
$DateFile=$_.CreationTime.Date
if ($DateFile -eq $CurrentDate1)
{
if ($File1Founded)
{
$_
}
else
{
$File1Founded=$true
}
}
elseif ($DateFile -eq $CurrentDate3)
{
if ($File3Founded)
{
$_
}
else
{
$File3Founded=$true
}
}
elseif ($DateFile -eq $CurrentDate7)
{
if ($File7Founded)
{
$_
}
else
{
$File7Founded=$true
}
}
else
{
$_
}
} | Remove-Item -WhatIf

tegrahost_v2: Stat for tegra186-quill-p3310-1000-c03-00-base.dtb failed

I've built an image for Jetson TX2 module using yocto. Everything when fine for few days but now I get this error when I try to flash the device.
Welcome to Tegra Flash
version 1.0.0
Type ? or help for help and q or quit to exit
Use ! to execute system commands
[ 0.0008 ] tegrasign_v2 --key None --getmode mode.txt
[ 0.0016 ] Assuming zero filled SBK key
[ 0.0016 ]
[ 0.0016 ] Generating RCM messages
[ 0.0023 ] tegrarcm_v2 --listrcm rcm_list.xml --chip 0x18 --download rcm mb1_recovery_prod.bin 0 0
[ 0.0030 ] RCM 0 is saved as rcm_0.rcm
[ 0.0033 ] RCM 1 is saved as rcm_1.rcm
[ 0.0033 ] List of rcm files are saved in rcm_list.xml
[ 0.0033 ]
[ 0.0033 ] Signing RCM messages
[ 0.0040 ] tegrasign_v2 --key None --list rcm_list.xml --pubkeyhash pub_key.key
[ 0.0046 ] Assuming zero filled SBK key
[ 0.0076 ]
[ 0.0076 ] Copying signature to RCM mesages
[ 0.0083 ] tegrarcm_v2 --chip 0x18 --updatesig rcm_list_signed.xml
[ 0.0093 ]
[ 0.0093 ] Parsing partition layout
[ 0.0100 ] tegraparser_v2 --pt flash.xml.tmp
[ 0.0109 ]
[ 0.0109 ] Creating list of images to be signed
[ 0.0116 ] tegrahost_v2 --chip 0x18 --partitionlayout flash.xml.bin --list images_list.xml zerosbk
[ 0.0124 ] Stat for tegra186-quill-p3310-1000-c03-00-base.dtb failed
[ 0.0161 ]
Error: Return value 4
Command tegrahost_v2 --chip 0x18 --partitionlayout flash.xml.bin --list images_list.xml zerosbk
Does this error ring a bell to anyone?
I am able to flash the board with JetPack.
Thanks,
-Damien
Just in case you never figured this out, it looks like
[ 0.0124 ] Stat for tegra186-quill-p3310-1000-c03-00-base.dtb failed
is the real error. Fix that and you should be good.

How to Wait for more Content when Reading a File with Factor?

I have something like the following code
"file.txt" utf8 <file-reader> [ [ print ] each-line ] with-input-stream* ;
This works nicely for the current contents of file.txt and the processing (like printing in this case) ends when the end-of-file is reached. But I want the process to wait for new contents appended to the file and also process this. Or in other words, the current version implements Unix cat, but I want it to do tail -f.
I hoped with-input-stream* (mind the asterisk) would do the trick, as the docs say the stream is not closed at the end. But there must be something else I'm missing.
You're in luck, I wrote a utility like that a while ago. See https://github.com/bjourne/playground-factor/wiki/Tips-and-Tricks-Filesystem#tailing-a-file
USING: accessors io io.encodings.utf8 io.files io.monitors kernel namespaces ;
IN: examples.files.tail
: emit-changes ( monitor -- )
dup next-change drop
input-stream get output-stream get stream-copy* flush
emit-changes ;
: seek-input-end ( -- )
0 seek-end input-stream get stream>> stream-seek ;
: tail-file ( fname -- )
[
dup f <monitor> swap utf8 [
seek-input-end emit-changes
] with-file-reader
] with-monitors ;
Your problem I think is that the quotation given to with-input-stream* will implicitly close the stream (each-line does it). I don't know if that is a bug or not. A word like this can be used to read the full stream without closing it:
: my-stream-contents* ( stream -- seq )
[ [ stream-read1 dup ] curry [ ] ] [ stream-exemplar produce-as nip ] bi ;
Then:
IN: scratchpad "/tmp/foo" utf8 <file-reader> [ my-stream-contents* print ] keep
file contents here
...
--- Data stack:
T{ decoder f ~input-port~ utf8 f }
IN: scratchpad my-stream-contents* print
more file contents here
...

Handling 4-block oriented matrix product and inversion in Maxima

I am concerned in finding symbolic solutions and expansion to matrix products and inversions. Actually, it is something I would like to define by myself. I will explain myself.
I want to create a "mathematical" object that i will call B4MAT which represents a square matrix whose elements are 4 square half-sized matrices. So I want to define the product between two B4MAT giving me back another B4MAT whose components are calculated by applying product rules, but among matrices, not scalars.
Furthermore, and this is a very important point, consider Blockwise Inversion of a matrix. I want to define inversion of a B4MAT as an operation returning me another B4MAT whose elements are calculated using the blockwise inversion algorithm in the link.
How to achieve this in Maxima?
Thankyou
For the first half of your question, you just need to change matrix_element_mult to non-commutative multiplication and then use a matrix whose elements are the blocks you want. For example:
Maxima branch_5_27_base_248_ge261c5e http://maxima.sourceforge.net
using Lisp SBCL 1.0.57.0.debian
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) A: matrix([1,2],[3,4])$ B: matrix([2,1],[3,4])$
(%i3) matrix([A,B], [B,A]);
*** output flushed ***
(%i4) C: matrix([A,B], [B,A]);
[ [ 1 2 ] [ 2 1 ] ]
[ [ ] [ ] ]
[ [ 3 4 ] [ 3 4 ] ]
(%o4) [ ]
[ [ 2 1 ] [ 1 2 ] ]
[ [ ] [ ] ]
[ [ 3 4 ] [ 3 4 ] ]
(%i5) C . C;
[ [ 5 5 ] [ 4 4 ] ]
[ [ ] [ ] ]
[ [ 18 32 ] [ 18 32 ] ]
(%o5) [ ]
[ [ 4 4 ] [ 5 5 ] ]
[ [ ] [ ] ]
[ [ 18 32 ] [ 18 32 ] ]
(%i6) matrix_element_mult: ".";
(%o6) .
(%i7) C . C;
[ [ 14 16 ] [ 13 17 ] ]
[ [ ] [ ] ]
[ [ 33 41 ] [ 33 41 ] ]
(%o7) [ ]
[ [ 13 17 ] [ 14 16 ] ]
[ [ ] [ ] ]
[ [ 33 41 ] [ 33 41 ] ]
I think you have to code up the inversion formula yourself though (don't forget you can get at the blocks with expressions like "C[1][2]" (for the top right corner) etc.

Resources