Badges

Types

Formats

Show Only

Awk Command
https://mreschke.com/225/awk-command
See also and Awk is a very powerfull line editor filter or small programming language available in all unix style operating systems. This page contains small tutorial awk scripts and snippets. Columns are automatically assigned $1 - $n. And $0 is the entire line Awk has some built in functions: gsub(r,s) globally replaces r with s within the line ($0) index(s,t) returns first position of string t in s (or 0 if not present) length(s) returns the number of characters in s match(s,r...
|
post #225 by mreschke Dec 4th 2010 (6841 views)
Windows Powershell
https://mreschke.com/259/windows-powershell
> Amazing script, this is for converting VHD's but it is an amazing reference, even build a GUI: http:www.ms4u.info/2012/06/create-sysprep-vhd-and-vhdx-for-windows.html (actual script http:gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f) How to even create and run a script file http:technet.microsoft.com/en-us/library/ee176949.aspx Basically enable local script execution with Set-ExecutionPolicy RemoteSigned Always run scripts with either their full path c:\test\scri...
|
post #259 by mreschke Jul 13th 2011 (3480 views)
Set Date Time in Linux
https://mreschke.com/253/set-date-time-in-linux
I need to adjust the date and time in linux quite often and sometimes its a pain to google the correct procedure of hardware clock and system clock. So here it is. This will change both your system clock and hardware clock together sudo date -s "7 JUN 2011 12:44:00"; sudo hwclock --systohc Show System Clock date Show Hardware Clock sudo hwclock --show Change System Clock sudo date -s "2 OCT 2006 18:00:00" Set Hardware Clock from System Clock sudo hwclock --systohc Set System Clock from Hardware...
|
post #253 by mreschke Jun 7th 2011 (3645 views)
PHP Snippets
https://mreschke.com/244/php-snippets
Small miscellaneous PHP code snippets and scripts while (list($key, $value) = each($_POST)) { echo "$key - $value"; }
|
post #244 by mreschke Apr 14th 2011 (2360 views)
Regular Expressions
https://mreschke.com/238/regular-expressions
http:msdn.microsoft.com/en-us/library/ms972966.aspx http:www.4guysfromrolla.com/articles/022603-1.aspx I have a large html file, I want to remove anything between the tags, even if the contents is on multiple lines. There is a regex option called RegexOptions.MultiLine which I though would work, but its actually the RegexOptions.Singleline below what makes it span multiple lines, see http:msdn.microsoft.com/en-us/library/ms972966.aspx for details on RegexOptions.Singleline. Dim reg As New Regex...
|
post #238 by mreschke Mar 8th 2011 (3281 views)
Sed Command
https://mreschke.com/226/sed-command
See Also and Replace all occurrence's in a file (and write back to the same file) sed -i "s/this/withthis/g" /tmp/somefile Replace output newline (carriage return) with sed ':a;N;$!ba;s/\n/ /g' emailbody="Your Directory`/bin/ls -Rhal $yourdir|sed ':a;N;$!ba;s/\ng'`"
|
post #226 by mreschke Dec 6th 2010 (3272 views)
EmailLogs.vbs
https://mreschke.com/213/emaillogsvbs
This script will email a log file (or any file specified) only if the file is under a certain size. If the file is over that size limit, it will still email, but no log will be attached. See Script does not use parameters, everything is hard coded, so just call the .vbs. Great in a scheduled task to email you a daily log file. Can easily be modified with parameters for various purposes. Option Explicit Dim iMsg, iConf, Flds, pc 'Email vars Dim logFile, maxLogSize 'Log vars Dim FSO, File, strSiz...
|
post #213 by mreschke Nov 10th 2010 (2818 views)
StartStopProc.vbs
https://mreschke.com/212/startstopprocvbs
This script will start or stop a process by process name. If the process is already running with a start is called, it will not start a duplicate. The benefit is that it will NOT start the script twice. So if you want to ensure an application is running all the time, just setup a scheduled task to run this script every 10 minutes, if the .exe dies it will start it, if the .exe is still running, it won't start a duplication. REM Example Script.bat (note I path to the .exe dir so it runs in its l...
|
post #212 by mreschke Nov 10th 2010 (2595 views)
DeleteOldFiles.vbs
https://mreschke.com/211/deleteoldfilesvbs
This script will recursively delete all files in every subfolder older than X days. Will not delete any folders, just files. I create a batch file and call the vbs script for any directory I need purged. rem Use this script to clean up any old files automatically. rem This .bat will be called weekly from a scheduled task, and will rem call the d:\production\batch\generic\DeleteOldFiles.vbs with directory/day parameters rem the commands will not run simultaneously (unless they begin with start)...
|
post #211 by mreschke Nov 10th 2010 (5065 views)
Python Tutorial
https://mreschke.com/195/python-tutorial
django installation on ubuntu server using WSGI http:blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/ works great! Great Tutorials http:code.google.com/edu/ and http:code.google.com/edu/languages/google-python-class/set-up.html #!/usr/bin/env python Tuples (like lists but immutable) mytuple = (1, 2, 'three') print len(mytuple) print mytuple #tuple = 'hi' #error, immutable def Foo(): tuple = ('one', 'two') return tuple test = Foo() print test (one, two)...
|
post #195 by mreschke Jul 9th 2010 (5435 views)
Linux Find Command
https://mreschke.com/132/linux-find-command
Ten usefull commands for FIND http:www.go2linux.org/usages-examples-of-find-command find ./ -name "*.mp3" this is casesensative find ./ -iname "*.mp3" this one is case-insensative find / -type d -print (to list only directories) find / -type l -print (to list only soft links) find / -type b -print (to list only bliock special files) find / -type f -print (to list only regular files)' find ./ -not -iname *.mp3 -not -iname *.jpg -not -iname *.jpeg like to find all junk thats not music or music re...
|
post #132 by mreschke Feb 17th 2009 (3155 views)
Batch File Snippets
https://mreschke.com/124/batch-file-snippets
@echo off FOR /F "TOKENS=1DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B FOR /F "TOKENS=1-5 DELIMS=:" %%d in ("%time%") DO SET h=%%d FOR /F "TOKENS=1-5 DELIMS=:" %%d in ("%time%") DO SET m=%%e FOR /F "TOKENS=1-5 DELIMS=:" %%d in ("%time%") DO SET s=%%f SET dateFilename=%yyyy%-%mm%-%dd%_%h%...
|
post #124 by mreschke Jan 16th 2009 (3176 views)
Linux SendEmail
https://mreschke.com/79/linux-sendemail
Not to be confused with linux sendmail. apt-get install sendEmail Create a bash script "sendemail" and run chmod 755 on it. #!/bin/sh export smtpemailfrom=zabbix@yourdomain.com export zabbixemailto=$1 export zabbixsubject=$2 export zabbixbody=$3 export smtpserver=yoursmtpserver.com export smtplogin=smtpuser export smtppass=smtppassword #Use this line if your SMTP server requires authentication /usr/bin/sendEmail -f $smtpemailfrom -t $zabbixemailto -u $zabbixsubject -m $zabbixbody -s $smtpserver:...
|
post #79 by mreschke Jun 30th 2008 (5245 views)
ProcessManager.vbs
https://mreschke.com/58/processmanagervbs
Very handy VBScript, watches a process during a certian time interval, if it's running good, if not start it unless it's beyond the time interval, then kill it. Good if you want a program to run between 1pm-5pm but not the rest of the time. Hook this up to a scheduled task and exec every 10 minutes to ensure app is running or app is dead. IF the process is down in the time frame, it will start it, and send out an email that it was down. See You must edit the script below. Must set the process t...
|
post #58 by mreschke May 6th 2008 (3320 views)
VBScript File List
https://mreschke.com/56/vbscript-file-list
<p>This script accepts a path (ex: c:\temp\*.* or c:\*.txt) and builds a 1 dimensional array of the files that match the directory/wildcard.</p>
|
post #56 by mreschke May 6th 2008 (3105 views)
VBScript Snippets
https://mreschke.com/55/vbscript-snippets
dim filesys set filesys=CreateObject("Scripting.FileSystemObject") If filesys.FileExists("c:\sourcefolder\anyfile.html") Then filesys.MoveFile "c:\sourcefolder\anyfile.html", "c:\destfolder\" End If Get the last modified date and time of a file Private Function FileDateTime(byVal pathname) Dim objFSO, objFile On Error Resume Next Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile(pathname) If Err Then FileDateTime = Null Else FileDateTime = CDate( objFil...
|
post #55 by mreschke May 6th 2008 (3037 views)
VBScript Basics
https://mreschke.com/46/vbscript-basics
function test() dim a a = "Hi there" test = a 'This returns a end function Option Explicit 'Check a process, restart it and send email alert, or kill process depending on time window 'Original script created by NetRes 'Modified by mReschke 2008-04-28 (converted to functions, actions change by time, email enhancements, globals, generic process killer) 'If process is NOT running between start/endHour then restart it and send an email if sendEmail = true 'If process is running outside of start/end...
|
post #46 by mreschke Apr 29th 2008 (3156 views)
Send Email using VBScript
https://mreschke.com/45/send-email-using-vbscript
This is just a function snippet, sends an email with attachments, must manually edit function with email and attachment parameters. Used in and Sub SendLogEmail() Set pc = CreateObject("Wscript.Network") Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") Set Flds = iConf.Fields Const schema = "http:schemas.microsoft.com/cdo/configuration/" dim emailBody Flds.Item(schema & "sendusing") = 2 Flds.Item(schema & "smtpserver") = "xxx.xxx.xxx.xxx" Flds.Item(schema & "...
|
post #45 by mreschke Apr 29th 2008 (6017 views)
Daemons and Runlevels
https://mreschke.com/41/daemons-and-runlevels
See LXF 114 p48, 'Banish Your Daemons' Runlevels are defined levels in which a linux operating system can start. Daemons (or services) are scripts/programs that run in the background constantly (like apache or mysql are services that are always running) and are usually executed at startup by the defined runlevel. Runlevels are identified by a number from 0 - 6, but each linux distribution may use those numbers a bit differently. Basically a runlevel determines which daemons to execute at startu...
|
post #41 by mreschke Apr 12th 2008 (13224 views)
Showing 1 to 19 of 19 results