<p>Team,
<code>/bin/bash: line 5: ./repo/clone.sh: No such file or directory</code></p>
<p>cannot run above file but I can cat it well. I tried my best and still trying to find but no luck so far..</p>
<p>my requirement is to mount bash script from config map to a directory inside container and run it to clone a repo but am getting below message.</p>
<p><strong>cron job</strong></p>
<pre><code>spec:
  concurrencyPolicy: Allow
  jobTemplate:
    metadata:
    spec:
      template:
        metadata:
        spec:
          containers:
          - args:
            - -c
            - |
              set -x
              pwd &amp;&amp; ls
              ls -ltr /
              cat /repo/clone.sh
              ./repo/clone.sh
              pwd
            command:
            - /bin/bash
            envFrom:
            - configMapRef:
                name: sonarscanner-configmap
            image: artifactory.build.team.com/product-containers/user/sonarqube-scanner:4.7.0.2747
            imagePullPolicy: IfNotPresent
            name: sonarqube-sonarscanner
            securityContext:
              runAsUser: 0
            volumeMounts:
            - mountPath: /repo
              name: repo-checkout
          dnsPolicy: ClusterFirst
          initContainers:
          - args:
            - -c
            - cd /
            command:
            - /bin/sh
            image: busybox
            imagePullPolicy: IfNotPresent
            name: clone-repo
            securityContext:
              privileged: true
            volumeMounts:
            - mountPath: /repo
              name: repo-checkout
              readOnly: true
          restartPolicy: OnFailure
          securityContext:
            fsGroup: 0
          volumes:
          - configMap:
              defaultMode: 420
              name: product-configmap
            name: repo-checkout
  schedule: '*/1 * * * *'
</code></pre>
<p><em><strong>ConfigMap</strong></em></p>
<pre><code>kind: ConfigMap
metadata:
apiVersion: v1
data:
  clone.sh: |-
    #!bin/bash
    set -xe
    apk add git curl
    #Containers that fail to resolve repo url can use below step.
    repo_url=$(nslookup ${CODE_REPO_URL} | grep Non -A 2 | grep Name | cut -d: -f2)
    repo_ip=$(nslookup ${CODE_REPO_URL} | grep Non -A 2 | grep Address | cut -d: -f2)
    if grep ${repo_url} /etc/hosts; then
        echo &quot;git dns entry exists locally&quot;
    else
        echo &quot;Adding dns entry for git inside container&quot;
        echo ${repo_ip} ${repo_url} &gt;&gt; /etc/hosts
    fi
    cd / &amp;&amp; cat /etc/hosts &amp;&amp; pwd
    git clone &quot;https://$RU:$RT@${CODE_REPO_URL}/r/a/${CODE_REPO_NAME}&quot; &amp;&amp; \
        (cd &quot;${CODE_REPO_NAME}&quot; &amp;&amp; mkdir -p .git/hooks &amp;&amp; \
        curl -Lo `git rev-parse --git-dir`/hooks/commit-msg \
        https://$RU:$RT@${CODE_REPO_URL}/r/tools/hooks/commit-msg; \
        chmod +x `git rev-parse --git-dir`/hooks/commit-msg)
    cd ${CODE_REPO_NAME}
    pwd
</code></pre>
<p><strong>output pod describe</strong></p>
<pre><code>  Warning  FailedCreatePodSandBox  1s    kubelet, node1  Failed create pod sandbox: rpc error: code = Unknown desc = failed to start sandbox container for pod &quot;sonarqube-cronjob-1670256720-fwv27&quot;: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused &quot;process_linux.go:303: getting the final child's pid from pipe caused \&quot;EOF\&quot;&quot;: unknown
</code></pre>
<p><strong>pod logs</strong></p>
<pre><code>+ pwd
+ ls
/usr/src
+ ls -ltr /repo/clone.sh
lrwxrwxrwx    1 root     root            15 Dec  5 16:26 /repo/clone.sh -&gt; ..data/clone.sh
+ ls -ltr
total 60
.
drwxr-xr-x    2 root     root          4096 Aug  9 08:58 sbin
drwx------    2 root     root          4096 Aug  9 08:58 root
drwxr-xr-x    2 root     root          4096 Aug  9 08:58 mnt
drwxr-xr-x    5 root     root          4096 Aug  9 08:58 media
drwxrwsrwx    3 root     root          4096 Dec  5 16:12 repo &lt;&lt;&lt;&lt;&lt; MY MOUNTED DIR
.
+ cat /repo/clone.sh
#!bin/bash
set -xe
apk add git curl
#Containers that fail to resolve repo url can use below step.
repo_url=$(nslookup ${CODE_REPO_URL} | grep Non -A 2 | grep Name | cut -d: -f2)
repo_ip=$(nslookup ${CODE_REPO_URL} | grep Non -A 2 | grep Address | cut -d: -f2)
if grep ${repo_url} /etc/hosts; then
    echo &quot;git dns entry exists locally&quot;
else
    echo &quot;Adding dns entry for git inside container&quot;
    echo ${repo_ip} ${repo_url} &gt;&gt; /etc/hosts
fi
cd / &amp;&amp; cat /etc/hosts &amp;&amp; pwd
git clone &quot;https://$RU:$RT@${CODE_REPO_URL}/r/a/${CODE_REPO_NAME}&quot; &amp;&amp; \
    (cd &quot;${CODE_REPO_NAME}&quot; &amp;&amp; mkdir -p .git/hooks &amp;&amp; \
    curl -Lo `git rev-parse --git-dir`/hooks/commit-msg \
    https://$RU:$RT@${CODE_REPO_URL}/r/tools/hooks/commit-msg; \
    chmod +x `git rev-parse --git-dir`/hooks/commit-msg)
cd code_dir
+ ./repo/clone.sh
/bin/bash: line 5: ./repo/clone.sh: No such file or directory
+ pwd
pwd/usr/src
</code></pre>

AhmFM
<p>Assuming the working directory is different thant <code>/</code>:</p>
<p>If you want to source your script in the current process of bash (shorthand <code>.</code>) you have to add a space between the dot and the path:</p>
<p><code>. /repo/clone.sh</code></p>
<p>If you want to execute it in a child process, remove the dot:</p>
<p><code>/repo/clone.sh</code></p>
