Forum Discussion

Wishaal's avatar
Wishaal
Cloud Apps
02-27-2023
Solved

Cronjob to copy files from local to K8

Hi All,

Currently I am using the following

kubectl cp /home/ftpifx sisense/`kubectl -n sisense get po -l 'app=management' | awk 'END { print $1 }'`:/opt/sisense/storage/data/informix/

command to copy files between our local system and the storage pod.

However, we want to automate the run of this.

We tried creating a bash script and adding this to the Linux crontab, but this doesn't run.

Is there another way to run this command automatically? 

  • Hi,

    You just need to create a bash script in order to make the copy. First of all, get the management pod name:

    #!/bin/bash
    
    localFolder=/path/to/local/files
    management=$(kubectl -n sisense get pods -l app="management" -o custom-columns=":.metadata.name")
    for fileName in `find $localFolder -name '*.csv' -exec basename {} \;` ; do
            kubectl -n sisense cp /home/ftpifx sisense/$fileName $management:/opt/sisense/storage/data/informix/$fileName
    done

    Then, you can add this script to the corntab (make this .sh script executable)

    Best

2 Replies

Replies have been turned off for this discussion
  • Hi,

    You just need to create a bash script in order to make the copy. First of all, get the management pod name:

    #!/bin/bash
    
    localFolder=/path/to/local/files
    management=$(kubectl -n sisense get pods -l app="management" -o custom-columns=":.metadata.name")
    for fileName in `find $localFolder -name '*.csv' -exec basename {} \;` ; do
            kubectl -n sisense cp /home/ftpifx sisense/$fileName $management:/opt/sisense/storage/data/informix/$fileName
    done

    Then, you can add this script to the corntab (make this .sh script executable)

    Best