GNU/Linux Bash Check Command Line Parameter
Example script with a check on the number of submitted parameters.
#!/bin/bash
[ $# -ne 1 ] && echo "ERROR: Input Required" && exit 1;
echo $1
Example script with a check on the number of submitted parameters.
#!/bin/bash
[ $# -ne 1 ] && echo "ERROR: Input Required" && exit 1;
echo $1
A simple bash-script for OpenShift to determine which deployment configs make use of a specific secret (within the active project).
#!/bin/bash
oc get dc -o custom-columns="Name:metadata.name,readyReplicas:status.availableReplicas,Volumes:spec.template.spec.volumes,env:spec.template.spec.containers[].env,envFrom:spec.template.spec.containers[].envFrom,Volumes:spec.template.spec.volumes" | grep -E "($1)" | grep -oE "^[a-z0-9-]{3,99}"
$ os-sec-usage.sh secretname
Recently wrote a simple function to add permission to filesystem resources. It defaults to modify permissions, but can also be another basic permission for instance: Read, Write or FullControl.
function fnAddFilesystemPermissions()
{
param (
[string]$sPath,
[string]$sUserName,
[string]$sPermission = "Modify"
)
# Add write permissions to a file using powershell...
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($sUserName,$sPermission,"Allow")
$acl = Get-ACL -Path $sPath
$acl.SetAccessRule($accessRule)
$acl | Set-Acl -Path $sPath
# Return permissions...
return (Get-ACL -Path $sPath).Access | Format-Table
}
PS> fnAddFilesystemPermissions -sPath “C:\Path\To\Resource” -sUserName “User-Principle-Name” [-sPermission “FullControl“]
Some commands I regularly use to start tools from the command line when I need them to start with elevated privileges.
My Frequently Used CLI Commands / Admin Tools (QuickRef) | Description |
---|---|
dsa.msc / adsiedit.msc / virtmgmt.msc | Active Directory Users & Computers / ADSI Edit / Hyper-V Manager |
start-process powershell -verb runas | Start PowerShell with Elevated Privileges |
rundll32 sysdm.cpl,EditEnvironmentVariables | Edit system environment variables |
cacls “C:\Path\To\File.TXT” /E /G username@example.com:C | Quick way to add write permission to a filesystem resource |
mvn clean package -DskipTests | Mavin compile (Java) code and create local package |
mvn test -Dtest=JavaClassTest#specificTest | Run a specific unit test from the command line |
java -Djavax.net.debug=ssl:handshake -jar target/packagename-1.0.0-SNAPSHOT.jar | Start package with TLS handshake debugging enabled |
oc create secret generic gateway1 –from-file=server.p12 | Create an OpenShift secret from the command line |
touch -t 202301251415.00 Filename | Force file timestamp to a specific datetime |
oc get pods | grep Evicted | awk ‘{print $1}’ | xargs oc delete pod | Delete evicted pods from current OpenShift project |