Saturday, June 22, 2019

Finding Windows Uptime from Command Line

To get Windows uptime from the command line, we can instead obtain the boot time of the system, and subtract it from current time. To obtain the boot time, we can do the following,

On a Windows server,

net statistics server | find "Statistics since" 


On a Windows workstation

net statistics workstation | find "Statistics since"


Alternatively, we can use the following,

systeminfo | find "System Boot Time:"

or

wmic path Win32_OperatingSystem get LastBootUpTime

or

echo (get-date) - (gcim Win32_OperatingSystem).LastBootUpTime | powershell

Friday, June 7, 2019

PostgreSQL Password File

To access a PostgreSQL database, we may use a Password file. We can place the Password file any where and references to it via a PGPASSFILE environment variable. Here is an example on Windows:



C:\Work>type ./pgpass
# hostname:port:database:username:password
foodbhost:5432:foodb:foouser:foopassword

C:\Work>set PGPASSFILE=./pgpass

C:\Work>psql -U foodbuser -h foodbhost foodb
psql (9.6.3)
Type "help" for help.

foodb=>

Using this method, we help separate the DB authentication and authorization from the application logic. 

Sunday, June 2, 2019

Making New Git Repository from Directories in Existing Git Repository

I want to make a new Git repository from a few directories in an existing Git repository. I found the solution provided in this Stack Overflow answer was exactly what I wanted.