Samurai
Samurai

Reputation: 139

Run shell script in pod remotely openshift or kubernetes

I have one shell script I want to run that remotely in POD, how I can do that?

 oc exec build-core-1-p4fr4 -- df -kh /   <---  I want to use my script 

any way to do this remotely, like we do

oc exec build-core-1-p4fr4 -- cat >> text << shell.sh <---- something like this 

I checked oc rsh but didn't find anything specific there.

Upvotes: 0

Views: 9368

Answers (2)

WesternGun
WesternGun

Reputation: 12827

Use oc exec -i to take script from stdin.

oc exec -i your_pod_name -- bash -s < your_script.sh

Upvotes: 3

Daein Park
Daein Park

Reputation: 4703

You can try the following command using -i option that allows to pass stdin to the container.

$ oc exec -i your_pod_name -- /bin/bash -s <<EOF
#!/bin/bash
date > /tmp/time
EOF

$ oc exec your_pod_name -- cat /tmp/time
Fri Nov 13 10:00:19 UTC 2020
$

Upvotes: 4

Related Questions