Help Center/ ModelArts/ FAQs/ Training Jobs/ Compiling the Training Code/ How Do I Invoke a Shell Script in a Training Job to Execute the .sh File?
Updated on 2022-12-06 GMT+08:00

How Do I Invoke a Shell Script in a Training Job to Execute the .sh File?

ModelArts enables you to invoke a shell script, and you can use Python to invoke .sh. The procedure is as follows:

  1. Upload the .sh script to an OBS bucket. For example, upload the .sh script to /bucket-name/code/test.sh.
  2. Create the .py file on a local PC, for example, test.py. The background automatically downloads the code directory to the /home/work/user-job-dir/ directory of the container. Therefore, you can invoke the .sh file in the test.py boot file as follows:
    import os
    os.system('bash /home/work/user-job-dir/code/test.sh')
  3. Upload test.py to OBS. Then the file storage path is /bucket-name/code/test.py.
  4. When creating a training job, set the code directory to /bucket-name/code/, and the boot file directory to /bucket-name/code/test.py.

After the training job is created, you can use Python to invoke the .sh file.