Wednesday, July 26, 2017

Do something and Log information to event log in Powershell

A quick way to generate a log file that can be used to feed write-eventlog
=========================================
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$Archivolog = "C:\temp\output-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
$Archivolog2 = "C:\temp\compress-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
Start-Transcript -path $Archivolog -append
Write-Host Step 1 Start at $(get-date)
gci -r C:\temp | where {$_.attributes -notmatch "compressed"} | foreach {compact /C $_.fullname }  | out-file $Archivolog2 -Append
gc $Archivolog2
Write-Host Step 1 Finished at $(get-date)
Stop-Transcript
$text = [IO.File]::ReadAllText($Archivolog)
New-EventLog –LogName Application –Source "Nakama test"
Write-EventLog –LogName Application –Source "Nakama test" –EntryType Information –EventID 9213  –Message $text
=========================================

0 comments:

Post a Comment

Sunday, February 12, 2017

Parse ACLs and comparison made between 2 files obtained through setacl.exe command

======================================================
copy wealth_source.csv source.csv /y
copy wealth_target.csv target.csv /y

sed -ie "/^\\\\/{n;d}" source.csv
sed -ie "s/   /;/g" source.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; source.csv >source2.csv
sed -i "/^\s*$/d" source2.csv
sed -ie "s/=/;/g" source2.csv
sed -ie "/.*;DACL/d"  source2.csv


awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" source2.csv >source3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" source3.csv >source4.csv

sed -ie "/^\\\\/{n;d}" target.csv
sed -ie "s/   /;/g" target.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; target.csv >target2.csv
sed -i "/^\s*$/d" target2.csv
sed -ie "s/=/;/g" target2.csv
sed -ie "/.*;DACL/d"  target2.csv
del sed *.

awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" target2.csv >target3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" target3.csv >target4.csv


awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" target4.csv >target5.csv
awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" source4.csv >source5.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\TargetServer\\software/,\"\",$1); print}" target5.csv >target6.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\OriginalServer\\Vol1/,\"\",$1); print}" source5.csv >source6.csv

sed -i "/^;/d" target6.csv
sed -i "/^;/d" source6.csv

awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV

awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" source6.csv target6.csv > Found-on-target.csv
sed -i "1 i\Value searched;File found on Target (Targetserver);Target Domain found;Target Group found;Target SID found;Target ACL found;Target ACL found;Target ACL found;Source value;Source file;Source Domain;Source group;Source SID;Source ACL;Source ACL;Source ACL" BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV

findstr /c:" Not Found" Found-on-target.csv >only-missings-on-source.csv

del sed *.
======================================================

Script on Windows with awk/sed to parse two files making a comparison between them.
Scenario: robocopied source to target
ReACL is required. Tool used: setacl.exe with mapping.csv file using OLDSID,NEWSID
This script removes what I don't care - Searches based on column or field 1: file/folder+GroupName, if not found it states not found.

0 comments:

Post a Comment

AWK vlookup on Windows in my case

I needed to process two files/sheets to find the matches or mark un-match as Not found or anything similar.
These are extremely long files which causes excel to take forever, or even crash everytime I ran a vlookup between these two sheets.

awk vlookup solution would be something like this
Assuming you have 2 files separated by semicolon as the demiliter.

awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV

If first column of both files are equal, print columns 1 to 8 from the target6.csv file, plus the entire line from source6.csv  if it is not found it will print the value we are looking plus "Not found" and then the entire line from source6.csv

0 comments:

Post a Comment

Sunday, February 7, 2016

SRT to VobSub

I bought a TV: Panasonic ET60 very nice but it does not handle subtitles very well, or I mean it is very limited (very small font, and not possible to change colors)

The solution would be to either hard copy the subtitles or use vobsub subtitles (idx+sub / vobsub is supported on this TV, I guess many DVD players and other Smart TV would be in the same conditions).

So I found two good solutions txt2vobsub or subtitlecreator.
I prefer subtitlecreator because the fonts look slightly better, but maybe that just me.
And finally use mkvmerge (incredible tool) to pack all together.

So I created two scripts, one for each case, you would need to download/extract and add that directory to your path (System environment) or you could copy all the files everytime.
Then copy for each case the .cmd to the directory where you have the movie and subtitle.
The script will look for .mp4 and .srt (same filename). You could edit or rename based on your preference.

(if you want to modify the font and size: for txt2vobsub just edit the batch fule and replace the name, I think it is set to Arial 24, if you want do this for SubCreator go to the data subfolder, edit the profile.xml, edit colors by changing the palette colors in hex format, this will also let you position the subtitle as required, with these settings it will work for 720p movies in general).

Download link: https://mega.nz/#F!GdsFAIJZ!PYvbKNfWL_ZpVEfTJogn2w


0 comments:

Post a Comment

Wednesday, May 6, 2015

Add the filename to each start of line on a file with SED

So you have a text file where you want to add the filename on each start of line for some reason so it can be easily managed as a csv or on Excel.

So do a dir /b > on the directory or create a list of files that require the filename as the begining of each line on those files:

In my example I have a bunch of file names inside asd.txt

for /f "tokens=*" %%i in (asd.txt) do sed "s/^/%%i;/" %%i

or

for /f "tokens=*" %%i in (asd.txt) do sed -i "s/^/%%i;/" %%i

That will add the filename and a semicolon

Such as:
file1;line1
file1;line2

And so on.


0 comments:

Post a Comment