Skip to content

Instantly share code, notes, and snippets.

View beancurd1's full-sized avatar

Beancurd beancurd1

View GitHub Profile
@beancurd1
beancurd1 / autostart.sh
Created March 8, 2020 03:19
CoreELEC or LibreELEC autostart.sh to auto start scripts upon reboot
# this located in /storage/.config/autostart.sh on a CoreELEC box, run chmod +x to make it executable
# use nohup to run the script in the backgroud
# nohup /storage/freemyip/updateDynDNS.sh &
# use this to run once off tasks
(
# pause few seconds to wait for network & time services to start
sleep 5
DT=$(date +"%m-%d-%Y, %r")
echo "Box rebooted on $DT, running tasks in autostart.sh" >> /storage/freemyip/DynDNSUpdate.log
@beancurd1
beancurd1 / Freemyip DYNU Dynamic IP Updater.sh
Last active November 10, 2021 15:27
Freemyip or DYNU Dynamic IP Updater Linux Bash Script, check external every 60 seconds (please change it to a LARGER value if you need to change to avoid blacklist). It runs as a auto-start job on my CoreELEC Amlogic S905 box
#!/bin/sh
# It calls an external python script sendmail.py to email the new IP out
# This should work on both bash and sh shells e.g. LibreELEC/CoreELEC
# DYNU Dynamic IP Updater
# https://wiki.libreelec.tv/useful_shell_scripts#dynu_dynamic_ip_updater
# Modified to update Freemyip DYNDNS
# Modify These for DYNU or other DynDNS services e.g. Freemyip, DuckDNS, etc.
DYNU_USERNAME="username"
@beancurd1
beancurd1 / InstallUpgradeRemove.bat
Last active July 4, 2018 12:32
This can be used to upgrade/downgrade/uninstall/deploy an application(s) via Shutdown/Startup scripts or GPO e.g. Immediate Task. Rem out the lines which useful to you.
::This script can be used to Upgrade, Downgrade, Remove or Deploy an application
::It extracts software GUID, then use the GUID to search it's related keys/values pairs
::This is the FASTEST Way to find out Name, Version & UninstallString
::Get DisplayName & DisplayVersion from 32bit (or 64bit) "Java 8 Update 172" or any software Uninstall GUID,
::End script (or you can use this to downgrade your version of Java), if both Name and Version found and matched.
::If Name found but version doesn't match, get the UninstallString, uninstall ALL 32bit (or 64bit) Java then install the one defined in script silently.
::If Name NOT found, then end script or you can install it
@echo off
setlocal ENABLEDELAYEDEXPANSION
@beancurd1
beancurd1 / QueryMSSQL.ps1
Created July 2, 2018 13:25
Query Microsoft SQL Server with Invoke-Sqlcmd Powershell cmdlet
##### Simple Way, return an array or string (if 1 item is returned) #######
$Date = @(Invoke-Sqlcmd -query "Select Convert(Varchar(11),Date,106) as Date From ValuationDate" -Server DBSERVER -Database DBNAME) | Select-Object -Expand Date
#####[ Another way to query MS SQL, it returns a Dataset Object ]#####
$SQLServer = "DBSERVER_NAME" #use Server\Instance for named SQL instances!
$SQLDBName = "DATABASE_NAME"
$SqlQuery = "Select something From A_TABLE"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
@beancurd1
beancurd1 / getLocalAdminsAV.vbs
Last active August 29, 2017 03:04
It collects Local Admin Users and AV on a machine and output the result to a csv file on a shared location. It can be assigned to logon or shutdown script.
' Created this for monthly compliance purpose, it collects Local Admin Users and AV on a machine
' Get software list from Registry Key. It can only list software installed by installer (*.exe & *.msi)
' Won't work with Preinstalled, Portable apps
' NOTE: I collected codes from few websites and didn't take a note of them. Please let me know
' if you found some portion of the code belongs to you. I will add a credit asap.
' REF: https://gallery.technet.microsoft.com/scriptcenter/8035d5a9-dc92-436d-a60c-67d381da15a3
If WScript.Arguments.Count <> 0 then
' assign parameter to strComputerName
strComputerName = WScript.Arguments(0)
@beancurd1
beancurd1 / AppLockerEventNotification.ps1
Created February 6, 2017 12:19
This is a script to send email notifications from Windows Scheduled Task when AppLocker events are logged in Forwarded Event log (a Windows Event Log which for centralize log collection, please refer to WEF for detail explanation). Please refer to the following webpage on how to pass event log variables from Scheduled Task to Powershell script h…
Param($eventFilePath)
# Get the first/latest event from "Forwarded Events" event log and
# Replace the field value and field name with meaningful value e.g. convert SID to proper user name and Full Name
$Event = Get-WinEvent -FilterHashtable @{Logname='ForwardedEvents'; Id=8004} -MaxEvents 1
If($Event.UserId.Value -eq $null)
{
return
} else {
$objSID = New-Object System.Security.Principal.SecurityIdentifier($Event.UserId.Value)
@beancurd1
beancurd1 / CheckPDFDate.ps1
Created January 1, 2016 03:43
A Powershell script which uses itextsharp.dll library to extract date from PDF files located on a network share and check whether they are valid. Email the result to people
# PDF Files Check Script (created by beancurd1, please distribute the code with this session, thanks)
# It uses itextsharp.dll (downloaded from SourceForge) to parse PDF files, extract the first date it found
# compare it against a predefined Date. Email the PDF file names to people if they doesn't match the predefined date
Add-Type -Path .\itextsharp.dll
$validDate = "11 Dec 2015"
$day = ([datetime]$validDate).ToString('dd') ; $day = $day -replace "^0", ""
#Define valid Month+Year format here, this will combine with $day in the search
$validMYArray = @(([datetime]$validDate).ToString(' MMM yyyy'))
@beancurd1
beancurd1 / DateManipulation.ps1
Created December 31, 2015 11:48
Powershell: Date Format, Conversion, Calculation
### [datetime] ALWAYS assumes MDY format irrespective of your culture when the following format is being converted
### therefore, it requires to use ParseExact in order correct this
[datetime]::ParseExact('9/11/2015','d/MM/yyyy', $null).ToString('dd MMM yyyy')
([datetime]'9 Dec 2015').ToString('dd MMMM yyyy')
Get-Date -Format 'dd MMM yyyy'
### Different ways of calculating TimeSpan
$StartDate = (GET-DATE)
$EndDate = [datetime]::ParseExact('22/12/2015','d/MM/yyyy', $null)
NEW-TIMESPAN –Start $StartDate –End $EndDate
@beancurd1
beancurd1 / Managing Backup GFS Retention.ps1
Created December 31, 2015 11:40
A useful script to manage GFS retention in multiple folders which contain backup files such as "backup_ddMMyyy.7z". It looks for backups done within a predefined year, then group them into Monthly, Weekly & Daily
# Created by beancurd1 (please distribute the code with this session, thanks)
# https://gist.github.com/beancurd1
# A useful script to manage GFS retention in a single folder which contains backup files
# such as "backup_ddMMyyy.7z". It looks for backups done within a year, then put them
# into Monthly, Weekly & Daily.groups
Clear
# Create a String array to store end of month dates for X months (e.g. 31DEC15 to 31JAN15)
# define how many years of data to retain (it will search files created in that year, split them into Monthly, Weekly and Daily)
$year=1