Lesson 3: Shell Scripts for Jobs

Lesson 3: Shell Scripts for Jobs

Users can use script files to run all commands during a job as well. For example, in the previous lesson, we manually inputted the command “ls” in the --command flag. However, we can simply add the “ls” command to a script file, and run that script file during the job.

Let’s make a script file in our local temp folder:

$ cd ~/tmp #this takes us to the temp folder
$ touch script.sh # this will create a new file named "script" with extension ".sh" in this folder

Now, let’s add some scripting to this file so that when opened it looks like:

$ cat /tmp/script.sh 
#!/bin/bash
pwd
ls -l
lscpu
free -h

We can now run a job using said script file:

$ lcli job run --name "execute script" --command "bash script.sh" \
--image lancium/ubuntu --cores 4 --mem 8 --input-file /tmp/script.sh

The following job spec is created:

{
    "id": 12653,
    "name": "execute script",
    "status": "created",
    "qos": 'high',
    "command_line": "bash script.sh",
    "image": "lancium/ubuntu",
    "resources": {
        "core_count": 4,
        "gpu_count": null,
        "memory": 8,
        "gpu": null,
        "scratch": null
    },
    "max_run_time": 259200,
    "input_files": [
        {
            "id": 1247,
            "name": "script.sh",
            "source_type": "file",
            "source": "/tmp/script.sh",
            "cache": false,
            "upload_complete": true,
            "chunks_received": [
                [
                    1,
                    37
                ]
            ]
        }
    ],
    "created_at": "2021-02-02T20:11:16.509Z",
    "updated_at": "2021-02-02T20:11:16.509Z"
}

Working with Custom Application Images