Set Date and time via command line

Let’s find out how to set Date and time via command line on linux and windows:

  • On Linux via terminal

    System time (Must have sudo privilege)
    date -s ‘2015-07-28 15:27:30’
    Hardware time
    Let’s set the hardware clock to the current system time:
    hwclock –systohc

  • On Windows via command prompt terminal

    System time (Must have Administrator privilege)
    date
    The current date is: 07/28/2015
    Enter the new date: (mm-dd-yy)_
    time
    The current time is: 15:34:03.44
    Enter the new time: _

Djamga – ShowUpAndPlaySports

What is Djamga – ShowUpAndPlaySports?

Djamga - ShowUpAndPlaySports

I have been playing soccer or football ever since I could walk. I played everywhere, in the streets growing up, in High school, in college, everywhere I go, I always figure out a way to play the beautiful game.

I also work as a Software Engineer and I started ShowUpAndPlaySports in 2009 to help people play pick up games in Calgary,AB, Canada. I then recreated the experience a few years later in Edmonton, AB, Canada. I started with 3 players and I now have more than 2400 players and counting in both cities.

Hard working professionals need to play team sports to stay active, network and just enjoy the beautiful games.

I was surprised how hard it was to find a pick up games in most cities in North America. So I decided to fix it.

After creating 2 successful Organized pick up sports league in Calgary and Edmonton, I wanted to help everybody in the world to find a place to play anytime. I have therefore created the App Djamga to do just that. You can use Djamga to find the following Pick Up or Drop in games around the world:

See android version below
See iOs version below

Download Android version below:
Get it on Google Play
 
Download iPhone version below:

Download Djamga App on iTunes App Store.

Replace all instances of a string in a file

Shell script to replace all instances of a string in a file on Linux & Windows.

  • On Linux via bash script

    sed “s/$stringToReplace/$replaceWith/g” $File_Name > $File_Name

  • On Windows using Powershell

    ( get-content $File_Name ) | % { $_ -replace $stringToReplace, $replaceWith } | set-content $File_Name

  • On Windows using Batch

    set str=teh cat in teh hat
    echo.%str%
    set str=%str:teh=the%
    echo.%str%

    Script Output:
    teh cat in teh hat
    the cat in the hat

  • On Windows or Linux using Perl

    perl -pi.orig -e “s///g;”

  • On Windows or Linux using Python

Source:

  1. http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir

Search all files containing a specific string

How to search all files containing a specific string on Linux and Windows?

  • On Linux

    grep -rnw ‘directory’ -e “pattern”
    grep –include=\*.{txt,log} -rnw ‘directory’ -e “pattern”
    This will only search for files with .txt or .log extension.
    grep –exclude=*.txt -rnw ‘directory’ -e “pattern”
    This will exclude files with .txt extensions.

  • On Windows

    CD Location
    FINDSTR /L /S /I /N /C:”pattern” *.log

Browse the internet via command line

How to browse the internet via command line on Linux and Windows?

  • On Linux

    lynx http://google.ca
    If you don’t have lynx on your linux installation, you will have to install it. On Linux Red hat, install it like this:
    yum list lynx (to check the availability of the package)
    yum -y install lynx (to install the package)
    you can also use: curl -0 http://yoursite/index.html to get the source code of a specific file.

  • On Windows

    start /max http://google.ca
    Will open the url using your default browser.

un-archive a folder silently in Windows

Powershell script to un-archive a folder silently in Windows

Let’s continue with our automation scripting tool series. Doing things on windows by using the mouse manually is fun until you run into the need to go to a major OS upgrade and have tons of applications to reinstall. To avoid human errors and save lots of time, you can write a script  to pick up your archived applications like tomcat zip files and unarchive it. This powershell scripts shows you how to unarchive a zip file silently.

#Unzip FIle Function
function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}

# Call the function to unzip

$Origin_Zip_File=”C:\Document\Test.zip”

$Destination_Folder=”C:\Document\Test_Unzipped”

Expand-ZIPFile –File $Origin_Zip_File –Destination $Destination_Folder

Script to Stop Application Pools on Windows

VB script to Stop Application Pools on Windows IIS 6

As  SysAdmin, We sometimes need to auto-stop some application pools in order to run a specific task like IIS logs cleanup.

This script will detect all application pools that are running and stop them.

=====================
myComputer = “.”
Set objWMIService = GetObject (“winmgmts:\\” & myComputer & “\root\microsoftiisv2”)
Set colItems = objWMIService.ExecQuery (“Select name from IISApplicationPoolSetting where AppPoolState = 2”)
For Each objItems In colItems
poolname=objItems.name
WScript.Echo poolname
AppPoolStop(poolname)
Next
Function AppPoolStop(PoolName)
set PoolcolItems = objWMIService.ExecQuery (“Select name from IISApplicationPool where name='” & poolname & “‘”)
For Each objItem In PoolcolItems
objitem.Stop
Next
End Function
===============
Enter that script in a text file, save it with extension “.vbs”. Copy it at C:\Windows\System32\
Run it manually or via a batch scheduler.
Thanks to Euk-marie. See the equivalent script by Euk-Marie to start the App Pool at https://www.eukhost.com/forums/f15/start-application-pool-simple-script-8937/

kill all processes used by a specific application or user

Shell script to kill all processes used by a specific application or user

On Linux servers, when applications are not correctly shut down, there are still some processes running and starting the application with those processes still running can result in the application not starting correctly or not functioning properly. It is imperative to always kill all lingering processes after shutting down an application.

If the list of  the lingering processes is long, it can be a pain to go through them one by one.

This shell script will kill them all in one command.

#!/bin/sh
#NOTE: Please don’t try this unless you have tried every thing else and there is no way else left.
# Run it as root
# For this example, you are running a oracle application using user account oracle.
# We assume that , there are not other application running under the account oracle.
kill -9 `ps -ef | grep oracle  | grep -v grep | awk ‘{print $2}’`