User:TiloWiki

  • my data

= Win scripts=

shutdown in 5min

  • %windir%\System32\Shutdown.exe /s /t 300

Find Serial Number

  • wmic bios get serialnumber (as admin CMD)

rename file with date

d:

cd D:\UserFiles\Tilo\Documents

ren HardwareMonitoring.hml HardwareMonitoring_%date%.hml

change energy

set /P turnoffM="Enter time in Minutes:"

POWERCFG -Change -monitor-timeout-ac %turnoffM%

ECHO Done %turnoffM%

pause

Check .Net version

  • powershell [http://stackoverflow.com/a/3495491/1747983 see here ]
  • gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | select -fi 1 -exp pschildname
  • gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | foreach-object {$_.name; $_.GetValue("Version");}

DHCP to Static

REM set to DHCP

netsh interface ip set address name="LAN" dhcp

netsh interface ip set dns name="LAN" dhcp

REM set to static

netsh interface ipv4 set address name="LAN" source=static address=192.168.0.83 mask=255.255.255.0 gateway=192.168.0.1 gwmetric=0

netsh interface ipv4 add address name="LAN" address=192.168.211.83 mask=255.255.255.0

netsh interface ipv4 set dns name="LAN" source=static address=192.168.0.4

netsh interface ipv4 add dns name="LAN" address=192.168.0.5

simple ping

  1. +-------------------------------------+
  2. +--2013-08-22 Tilo, simple ping script
  3. With rounding of Avg
  1. Start ###

$CompName = "google.com","steampowered.com","yahoo.com","64.59.144.90"

$TestCount = 400

$MyDate = Get-Date -format s

$OutputFile = "C:\log\" +(get-date -f yyyy-MM-dd)+ "_ping_result.txt"

foreach ($comp in $CompName) {

$test = Test-Connection -ComputerName $comp -Count $TestCount | measure-Object ResponseTime -Minimum -Maximum -Average

$response = ($test -as [int] )

"{0} Count: {1} Min/Avg/Max {2} / {3:N1} / {4} ms, Server: {5}" -f $MyDate, $TestCount, $test.Minimum, $test.Average, $test.Maximum, $comp >> $OutputFile

}

  1. End of the script ###

simple ping 2

$hostnames = "rko24","192.168.7.11","192.168.7.99","192.168.7.77","cpdb2.mydev.com" ,"192.168.7.25","192.168.7.26"

  1. $pingcmd = 'test-netconnection -port 515'

$pingcmd = 'test-connection'

$sleeptime = 300 #in sec

while ($true) {

# if (invoke-expression "$pingcmd $($hostname)") {

foreach ($hostname in $hostnames) {

if (& $pingcmd -count 2 $hostname -ea 0) {

Write-Host -ForegroundColor Green "$(Get-Date -format s) $hostname is up"

} else {

Write-Host -ForegroundColor Red "$(Get-Date -format s) $hostname is down !!!"

}

}

echo "sleep now for $sleeptime sec"

start-sleep $sleeptime

}

cleanup VCRedist

  • run with admin priv

VCRedist from VC++ 2008 installs temporary files in system root directory

c:

REM or D drive d:

cd\

del install.exe

del install.res.1028.dll

del install.res.1031.dll

del install.res.1033.dll

del install.res.1036.dll

del install.res.1040.dll

del install.res.1041.dll

del install.res.1042.dll

del install.res.2052.dll

del install.res.3082.dll

del vcredist.bmp

del globdata.ini

del install.ini

del eula.1028.txt

del eula.1031.txt

del eula.1033.txt

del eula.1036.txt

del eula.1040.txt

del eula.1041.txt

del eula.1042.txt

del eula.2052.txt

del eula.3082.txt

del vc_redist.msi

del vc_redist.cab

del VC_RED.cab

del VC_RED.msi

move msdia80.dll "c:\Program Files\Common Files\Microsoft Shared\VC\"

regsvr32 "c:\Program Files\Common Files\Microsoft Shared\VC\msdia80.dll"

pause

=Linux scripts=

  • sudo shutdown now -P

check temp

  • just run in terminal the part

  1. ! /bin/bash
  2. Records the CPU temp and writes it to a temporary file.

while [ 1 ]; do

CPUtemp=$(sensors | awk '/Physical id 0/{k=int($4)}END{print k}' )

GPUInfo=$(nvidia-smi --query-gpu=temperature.gpu,fan.speed,memory.free --format=csv,noheader)

echo "$(date +%Y-%m-%d_%H:%M:%S), $GPUInfo, $CPUtemp" >> /home/tilo/TempLog/`date +%Y%m%d`_Tilo_tempList.csv

sleep 90;

done

  • nvidia-smi (for overview)
  • nvidia-smi -q (for flat list)
  • nvidia-smi --help-query-gpu

  1. ! /bin/bash
  2. Records the CPU temp and writes it to a temporary file.

while [ 1 ]; do

CPUtemp=$(sensors | awk '/Physical id 0/{k=int($4)}END{print k}' )

GPUInfo=$(nvidia-smi --query-gpu=temperature.gpu,fan.speed,power.draw,clocks.gr,clocks.sm,clocks.mem,clocks.video,pstate,clocks_throttle_reasons.active,clocks_throttle_reasons.gpu_idle,clocks_throttle_reasons.applications_clocks_setting,clocks_throttle_reasons.sw_power_cap,clocks_throttle_reasons.hw_slowdown,memory.used,memory.free --format=csv,noheader)

echo "$(date +%Y-%m-%d_%H:%M:%S),$CPUtemp, $GPUInfo " >> /home/tilo/TempLog/`date +%Y%m%d`_Tilo_tempListv2.csv

sleep 90;

done

fix playlist

  1. !/bin/bash

cat "/home/user/Music/Playlists/DEU Dame.m3u" | grep -v '#' | \

while read i; do cp "${i}" /media/usbstick/_Songs ; done

namebench

DNS speed check

namebench 127.0.1.1 64.59.144.17 64.59.144.18 64.59.144.16 64.59.144.19 8.8.8.8 8.8.4.4 208.67.220.220 208.67.222.222 156.154.70.1 156.154.71.1 216.146.35.35 216.146.36.36 -x -w -i alexa -q 300 -O

Check db loop

for i in `ls *.db`; do

echo Start "${i}"

sqlite3 "${i}" "PRAGMA integrity_check"

echo Finish "${i}"

done

miniDLAN start

  1. !/bin/sh -e
  2. rc.local
  3. This script is executed at the end of each multiuser runlevel.
  4. Make sure that the script will "exit 0" on success or any other
  5. value on error.
  6. In order to enable or disable this script just change the execution
  7. bits.
  8. By default this script does nothing.

echo `date +%Y-%m-%d_%H%M%S`____$(uname -n)____Start on $(date) > /tmp/t-bootup.log

ping localhost -i 5 -c 5 >> /tmp/t-bootup.log

sleep 10

sudo /etc/init.d/minidlna restart >> /tmp/t-bootup.log

echo `date +%Y-%m-%d_%H%M%S`____$(uname -n)____Finish on $(date) >> /tmp/t-bootup.log

exit 0

= SQL=

Group by date

SELECT COUNT (*)

FROM [fnos_myos].[dbo].[QueueItem]

GO

SELECT COUNT(*),retry_count

FROM [fnos_myos].[dbo].[QueueItem]

Group by (retry_count)

GO

SELECT COUNT(*) as count ,Year(create_date) as Year, Month(create_date) as Month

FROM [fnos_myos].[dbo].[QueueItem]

GROUP BY Year(create_date), Month(create_date)

Order by Year(create_date), Month(create_date)

GO

Array loop

DECLARE @dbname VARCHAR(50) -- database name

DECLARE @filepath VARCHAR(256) -- path for files

DECLARE @fileName VARCHAR(256) -- filename for backup

DECLARE @targetDATApath VARCHAR(256) -- path for target files

SET @targetDATApath = 'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\'

DECLARE @targetDATAfile VARCHAR(256) -- filename for data file

DECLARE @targetDATAlogfile VARCHAR(256) -- filename for log file

DECLARE @logname VARCHAR(256) -- logname

DECLARE @dbnameslist table(dbnameTmp VARCHAR(50))

insert into @dbnameslist (dbnameTmp) values ('mydb1')

insert into @dbnameslist (dbnameTmp) values ('mydb2')

insert into @dbnameslist (dbnameTmp) values ('mydb3')

insert into @dbnameslist (dbnameTmp) values ('mydb5')

SET @filepath = 'D:\Backup\mydbs\'

DECLARE db_cursor CURSOR FOR

SELECT dbnameTmp

FROM @dbnameslist

OPEN db_cursor

FETCH NEXT FROM db_cursor INTO @dbname

WHILE @@FETCH_STATUS = 0

BEGIN

SET @fileName = @filepath + @dbname + '.BAK'

SET @targetDATAfile = @targetDATApath + @dbname + '.mdf'

SET @targetDATAlogfile = @targetDATApath + @dbname + '_log.ldf'

SET @logname = @dbname + '_log'

RESTORE DATABASE @dbname FROM DISK = @fileName WITH FILE = 1, MOVE @dbname TO @targetDATAfile , MOVE @logname TO @targetDATAlogfile

FETCH NEXT FROM db_cursor INTO @dbname

END

CLOSE db_cursor

DEALLOCATE db_cursor

--End restore

=Powershell=

Gen SQL statement

  • simple SQL generator

  1. PowerShell to generate SQL statements

$ListOfDBs = 'myDB1','myDB2','myDB3'

$OutPutFile = 'C:\myScripts\SQLstatement.sql'

$BackupPath = 'C:\temp'

$RestorePath = 'F:\temp'

$NewDataDIR = 'M:\MSSQL12.MSSQLSERVER\MSSQL\DATA'

$NewLogDIR = 'L:\MSSQL12.MSSQLSERVER\MSSQL\Data'

Add-Content $OutPutFile "--backup"

foreach ($Db in $ListOfDBs){

Add-Content $OutPutFile "BACKUP DATABASE $Db TO DISK = `'$BackupPath\$Db.bak`' WITH CHECKSUM, NAME = `'$($Db)_FullDBBackup`' ;"

}

Add-Content $OutPutFile "--Check Content Of backup"

foreach ($Db in $ListOfDBs){

Add-Content $OutPutFile "RESTORE FILELISTONLY FROM DISK = `'$RestorePath\$Db.bak`' ;"

}

Add-Content $OutPutFile "--restore"

Add-Content $OutPutFile '--restore Backup with FG need extra line'

foreach ($Db in $ListOfDBs){

Add-Content $OutPutFile "RESTORE DATABASE $Db FROM DISK = `'$RestorePath\$Db.bak`' WITH MOVE `'$Db`' TO `'$NewDataDIR\$Db.mdf`', MOVE `'$($Db)_log`' TO `'$NewLogDIR\$($Db)_log.ldf`' ;"

}

Add-Content $OutPutFile "--change comp level"

foreach ($Db in $ListOfDBs){

Add-Content $OutPutFile "ALTER DATABASE $Db SET COMPATIBILITY_LEVEL = 120 ;"

}

Add-Content $OutPutFile "--list orphan user"

foreach ($Db in $ListOfDBs){

Add-Content $OutPutFile "USE $Db ; EXEC sp_change_users_login 'Report' ;"

}

Mod files

$File = get-item myFile.txt

$FileContent = Get-Content $File -ReadCount 50000

$FileNameOrig = $File.basename

[GC]::Collect()

$FileContent = ForEach-Object {$FileContent.TrimEnd().replace('something1', ).replace('something2', ) }

[GC]::Collect()

Echo "Just trimmed"

$FileContent = $FileContent | where {$_ -ne ""}

echo "now write content"

set-content "$($FileNameOrig)_Out.txt" $FileContent -Encoding ASCII #UTF8

$FileContent = "null and nothing"

[GC]::Collect()

echo "done"

Create test files

100..150 | % { New-Item -Path C:\My_test_folder -Name "TestFile$_.txt" -Value "$(Get-Date -format s) This is Test File $($_) from $($env:username) on $($env:COMPUTERNAME)" -ItemType file}

Get Hash

gci *.iso | select FullName | %{get-Filehash -Algorithm md5 -Path $_.FullName ; get-FileHash -Algorithm sha1 -Path $_.FullName ; get-FileHash -Path $_.FullName} | format-table

Azure Runbook

  1. Tilo Runbook quick hack.
  1. add to Automation Account under Shared Resources "Default Automation Credential" which has access to start VMs
  2. Add to VM tag: MyAutoStartPrio with a number
  1. Get account

$azureCredential = Get-AutomationPSCredential -Name "Default Automation Credential"

if($azureCredential -ne $null)

{

Write-Output "$(Get-Date -format s) :: Attempting to authenticate as: [$($azureCredential.UserName)]"

}

else

{

throw "$(Get-Date -format s) :: No cred asset with name 'Default Automation Credential' was found. Specify a stored credential asset"

}

  1. Connect:
  2. Connect-AzureAD -Credential $azureCredential

Login-AzureRmAccount -Credential $azureCredential

  1. :List all subs which are enabled
  2. $AllSubID = (Get-AzureRmSubscription | Where {$_.State -eq "enabled"}).SubscriptionId

$AllSubID = (Get-AzureRmSubscription).SubscriptionId

Write-Output "$(Get-Date -format s) :: List of Subscription below"

$AllSubID

$AllVMList = @()

Foreach ($SubID in $AllSubID) {

Select-AzureRmSubscription -Subscriptionid "$SubID"

$VMs = Get-AzureRmVM | Where-Object { $_.tags.MyAutoStartPrio -ne $null }

Foreach ($VM in $VMs) {

$VM = New-Object psobject -Property @{`

"Subscriptionid" = $SubID;

"ResourceGroupName" = $VM.ResourceGroupName;

"MyAutoStartPrio" = $VM.tags.MyAutoStartPrio;

"VMName" = $VM.Name}

$AllVMList += $VM | select Subscriptionid,ResourceGroupName,VMName,MyAutoStartPrio

}

}

$AllVMListSorted = $AllVMList | Sort-Object -Property MyAutoStartPrio

Write-Output "$(Get-Date -format s) :: Sorted VM start list"

$AllVMListSorted

  1. Start VMs block

Write-Output "$(Get-Date -format s) :: Start VM now"

Foreach ($VM in $AllVMListSorted) {

Write-Output "$(Get-Date -format s) :: Start VM: $($VM.VMName) :: $($VM.ResourceGroupName) :: $($VM.Subscriptionid)"

Select-AzureRmSubscription -Subscriptionid $VM.Subscriptionid

Start-AzureRmVM -ResourceGroupName $VM.ResourceGroupName -Name $VM.VMName

Start-Sleep -s 120

}

Write-Output "$(Get-Date -format s) :: Done VM start"

Lastitem

=python=

  1. Start of script
  2. redir in cron job
  3. 0 2,8,14,20 * * * python /home/osmc/MyScript/DuolingoVacation.py >> /home/osmc/MyScript/log/DuoVac_$(date +\%Y\%m\%d).log

import logging

import sys

import duolingo

ScriptName = 'Duolingo Vacation'

USER='MyUserName here'

logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',level=logging.INFO,stream=sys.stdout)

logging.info('=========Start Script: ' + (ScriptName))

  1. Login/pick user.
  2. lingo = duolingo.Duolingo(USER)

lingo = duolingo.Duolingo(USER, password='My password here')

logging.info('Logon as: ' + (USER))

  1. Simple stuff Lang

Mylanguages = lingo.get_languages(abbreviations=False)

logging.info('Languages: ' + str(Mylanguages))

  1. Simple stuff Get streak info

streak_info = lingo.get_streak_info()

logging.info('streak_info: ' + str(streak_info))

  1. Buy Freeze

BuyStreak = lingo.buy_streak_freeze()

logging.info('streak_buy: ' + str(BuyStreak))

logging.info('=========End Script: ' + (ScriptName))

=Test=

a sig

TiloWiki (talk) 22:31, 8 August 2018 (UTC)