> For the complete documentation index, see [llms.txt](https://code.janardhanpulivarthi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code.janardhanpulivarthi.com/ubuntu/curl.md).

# curl

How to use curl

```bash
curl -s -X POST -H "Content-Type: application/json" --data-binary @gsc-request.json \
"https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}" > task4-gcs.result
```

Example api doc: <https://cloud.google.com/speech-to-text/docs/samples/speech-transcribe-async-gcs>

```bash
curl http://download.tensorflow.org/example_images/flower_photos.tgz \
    | tar xz
```

```bash
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`
```

```bash
curl -sLO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
chmod +x kops-linux-amd64
mv kops-linux-amd64 $WORK_DIR/bin/kops
```

```bash
for ((i=1;i<=10;i++)); do echo total_time: $(echo "`curl -s -o /dev/null -w '1000*%{time_total}\n' -s http://35.232.156.42`" | bc); done

#output
total_time: 203.000
total_time: 199.000
total_time: 199.000
total_time: 199.000
total_time: 200.000
total_time: 199.000
total_time: 199.000
total_time: 199.000
total_time: 206.000
total_time: 200.000
```

## grep

```bash
$ kubectl get pods | grep hello-
hello-687bb4b8f4-2fxwb      1/1     Running   0          20s
hello-687bb4b8f4-8q2sc      1/1     Running   0          11m
hello-687bb4b8f4-f4qnm      1/1     Running   0          11m
hello-687bb4b8f4-rmvkh      1/1     Running   0          20s
hello-687bb4b8f4-sh268      1/1     Running   0          11m
$ kubectl get pods | grep hello- | wc -l
5
```

## jsonpath

```bash
kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
```

```bash
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version
```

## Load testing

```bash
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
```

### mkdir

```bash
~ $ mkdir demo-directory && $_
~/demo-directory $
```

### Cert checking

```bash
# find <directory-name>
find ../02_ingest/ -type f -exec sed -i "s/curl /curl -k /" {} \;
```

### openssl

[X.509 v3 certificate](https://tools.ietf.org/html/rfc5280) and encoded in base64. A 2048-bit RSA key pair and wraps the public key in a self-signed certificate that is valid for 365 days with openssl.

```bash
openssl req -x509 -nodes -newkey rsa:2048 -days 365 \
    -keyout /path/to/private_key.pem \
    -out /path/to/public_key.pem \
    -subj "/CN=unused"
```

### Replacement

{% code title="translation-request.json" %}

```javascript
{
  "q": "your_text_here",
  "target": "en"
}
```

{% endcode %}

{% code title="ocr-response.json" %}

```javascript
"text": "A LE BIEN PUBLIC\nles dépêches\nPour Obama,\nla moutarde\nest\nde Dijon\n"
```

{% endcode %}

```bash
STR=$(jq .responses[0].textAnnotations[0].description ocr-response.json) && STR="${STR//\"}" && sed -i "s|your_text_here|$STR|g" translation-request.json
```
