Execute shell script file using kubernetes as a cron job

+1 vote

When executing yaml file as a cronjob i am getting the following error:

container_linux.go:247: starting container process caused "exec: \"/home/ubuntu/exam.sh\": stat /home/ubuntu/exam.sh: no such file or directory"
job2.yaml file apiVersion: batch/v1beta1 kind: CronJob metadata:   name: ghost   labels:
    role: blog spec:   schedule: "*/1 * * * *"   jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: ghost
            image: ghost:0.11-alpine
            command: ["/home/ubuntu/exam.sh"]
          restartPolicy: OnFailure

Can any one help me out of this.

Sep 27, 2018 in Kubernetes by Hannah
• 16,420 points
2,654 views

4 answers to this question.

+1 vote
Best answer

use /bin/sh instead of /bin/bash

This solved it for a lot of people. Have a look at this GitHub thread.

answered May 7 by Sid

selected May 7 by Kalgi
0 votes

With this kind of errors, you should check if the file was really executed by a cronjob, if it exists and is executable. Please check it.

Alternatively, you can run it from kubectl run command:

kubectl run ghost --schedule="*/1 * * * *" --restart=OnFailure --image=ghost:0.11-alpine -- /bin/sh -c "your check script content"
answered Sep 27, 2018 by Kalgi
• 42,430 points
+1 vote
Try updating your docker and check if the error still exists
answered May 7 by Manasi
+1 vote
I had the same error on windows. Resolved this by running docker as administrator. I don't the how and why behind it though.
answered May 7 by Yamini

Related Questions In Kubernetes

0 votes
1 answer

Connect to existing pod, execute script, disconnect - Kubernetes cron job

As far as i know there's no ...READ MORE

answered Sep 17, 2018 in Kubernetes by Kalgi
• 42,430 points
879 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Spark job using kubernetes instead of yarn

I should be in the format of ...READ MORE

answered Sep 6, 2018 in Kubernetes by Kalgi
• 42,430 points
129 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
3,044 views
+3 votes
1 answer
0 votes
3 answers

Using multiple commands in a kubernetes yaml file

Try something like this: containers: - name: ...READ MORE

answered Apr 23 in Kubernetes by lyza
6,497 views
0 votes
2 answers