Skip to content

Instantly share code, notes, and snippets.

@DigitalDuquette
Last active February 28, 2025 18:11
Show Gist options
  • Save DigitalDuquette/17b931d0ca5ca3ecf852fa852f6035c4 to your computer and use it in GitHub Desktop.
Save DigitalDuquette/17b931d0ca5ca3ecf852fa852f6035c4 to your computer and use it in GitHub Desktop.
Terminal Commands

Terminal Commands

I've yet to find the right snippet program to make access easy. Tossing into these quick files here for future reference.

:: View CPU and Memory via SSH on remote machine
typeperf "\Processor(_Total)\% Processor Time" -sc 1
typeperf "\Memory\Available MBytes" -sc 1
:: check logged in users on computer with ssh connection
query user
:: check logged in users on a remote server
query user /server:WEB3
:: log off using session ID from above and name the server
logoff 3 /server:WEB3
:: Run scheduled task on remote server
schtasks /Run /S ServerName /TN "\Folder\Task name"
:: List scheduled task on remote server
schtasks /Query /S ServerName /FO LIST /V
# Check who is logged into a remote computer via SSH:
Get-CimInstance -ClassName Win32_Process -Filter "Name = 'sshd.exe'" | Get-CimAssociatedInstance -Association Win32_SessionProcess | Get-CimAssociatedInstance -Association Win32_LoggedOnUser | Where-Object {$_.Name -ne 'SYSTEM'}
# everyone logged into a server:
Get-CimInstance -ClassName Win32_LogonSession | Get-CimAssociatedInstance -Association Win32_LoggedOnUser | Where-Object {$_.Name -ne 'SYSTEM'}
# query user from local machine
Invoke-Command -ComputerName MG1 -ScriptBlock { query user }
# View memory
Get-CimInstance Win32_OperatingSystem | Select-Object FreePhysicalMemory,TotalVisibleMemorySize
######################
# Scheduled Tasks
# List all scheduled tasks with their folder paths
Get-ScheduledTask | Select-Object TaskName, TaskPath, State | Format-Table -AutoSize
Get-ScheduledTask -TaskPath "\PADNOS\pipeline\" | Format-Table
Start-ScheduledTask -TaskPath "\PADNOS\pipeline\" -TaskName "freshservice_to_warehouse_projects"
# Check latest run time for a scheduled task
Invoke-Command -ComputerName "ServerName" -ScriptBlock { (Get-ScheduledTaskInfo -TaskName "\Folder\task").LastRunTime }
# Table of tasks in PADNOS task folder
Invoke-Command -ComputerName "ServerName" -ScriptBlock { Get-ScheduledTask -TaskPath "\PADNOS\" | Format-Table }
# Add LastRunTime to the table
Invoke-Command -ComputerName "ServerName" -ScriptBlock {
Get-ScheduledTask -TaskPath "\PADNOS\" |
ForEach-Object {
$_ | Select-Object TaskName, State, @{Name="LastRunTime";Expression={($_ | Get-ScheduledTaskInfo).LastRunTime}}
} | Format-Table -AutoSize
}
# Memory of a gold fish.
##################################################################
## VENV on macOS with Pyenv ######################################
# Make sure the version needed is installed
pyevn versions
# CD to repo
cd /path/to/repo
# Set local python version for repo:
pyenv local 3.11.10
pyenv virtualenv myproject-venv
pyenv local myproject-venv
#verify
python --version
# .venv ##########################################################
# create venv
python -m venv .venv
# activate
source .venv/bin/activate
##################################################################
## Venv on Windows ###############################################
python -m venv .venv
# Activate
.venv\Scripts\activate
# Note, when running via ssh to see output execute via:
# Activate .venv, see (.venv) PS C:\path>
.\.venv\Scripts\python.exe .\script.py
###################################################################
# load the requirements
pip install -r requirements.txt
#######################################################################################################
# SSH commands
#######################################################################################################
ssh username@colo_compute
#######################################################################################################
# User management
#######################################################################################################
# check logged in users on computer with ssh connection
query user
# check logged in users on a remote server
query user /server:WEB3
# log off using session ID from above and name the server
logoff 3 /server:WEB3
#######################################################################################################
# WINDOWS | task scheduler
#######################################################################################################
# Run scheduled task on remote server
schtasks /Run /S ServerName /TN "\Folder\Task name"
# Check status of a task
schtasks /Query /S ServerName /TN "\Folder\Task name" /v /fo LIST
#######################################################################################################
# Managing Files
#######################################################################################################
# Execute permissions to file
chmod +x file.sh
# Copy file directory
realpath file_name.txt | pbcopy
#######################################################################################################
# Network Utilities
#######################################################################################################
# check external IP address
curl checkip.amazonaws.com
# list all network services
networksetup -listallnetworkservices
# check status of a listed service. Replace "Wi-Fi" with the service name
networksetup -getinfo Wi-Fi
# Perform a quality test of network (speed)
networkQuality
#######################################################################################################
# Python CLI
#######################################################################################################
# Check installed python versions
brew list | grep python
brew install python
brew install pyenv
pyenv install 3.8.5 # replace with desired number
pyenv global 3.8.5 # sets the global env.
# VENV
python3 -m venv .venv
# activate
source .venv/bin/activate
# deactivate
deactivate
#######################################################################################################
# GitHub CoPilot in CLI
#######################################################################################################
# https://github.com/github/gh-copilot?tab=readme-ov-file
gh copilot suggest "Instal git"
gh copilot explain "traceroute github.com"
#######################################################################################################
# git
#######################################################################################################
# check what is going to be added to the commit
git status
# adds all files, changes, deletes to the commit
git add .
# adds a specific file to the commit. Needed when the file is not yet in the commit
git add file_name
# commit the change with a message
git commit -m "commit message"
# use the AI for message creation
aicommits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment