Last active
August 7, 2019 02:34
-
-
Save rfvgyhn/55c146dcc2615261e004c28cc987a425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
action=${1:-resume} | |
case "$action" in | |
resume) action_past_tense="resumed" ;; | |
suspend) action_past_tense="suspended" ;; | |
*) echo "Invalid argument. Specify resume (default) or suspend" ; exit 2 | |
esac | |
echo "Enter db password:" | |
readarray -t lines <<< $(keepassxc-cli show /path/to/db.kdbx teslamate-web -q -a UserName -a Password) | |
status=$(curl -X PUT -s -o /dev/null -w "%{http_code}" --url "https://yourdomain.com/api/car/1/logging/resume" -K- <<< "user = ${lines[0]}:${lines[1]}") | |
[[ $status -eq 204 ]] && echo "Logging $action_past_tense" || echo "Error: HTTP $status" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
$domain = "https://yourdomain.com" | |
$vehicleId = 1 | |
$args = @{ | |
#Credential = Get-Credential -Message $domain # Uncomment if your server uses basic auth | |
Uri = "$domain/api/car/$vehicleId/logging/resume" | |
Method = "PUT" | |
ErrorAction = "Stop" | |
} | |
Invoke-WebRequest @args *>$null | |
"Success: Logging resumed" | |
} | |
catch | |
{ | |
$statusCode = $_.Exception.Response.StatusCode.value__ | |
$statusReason = $_.Exception.Response.StatusDescription | |
"Error: $statusCode - $statusReason" | |
"Press any key to continue..." | |
[void][System.Console]::ReadKey($true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment