> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/sast-and-sca/ocular/execute-startup-scripts.md).

# Execute Scripts on Startup

When starting Ocular, you can choose to have scripts automatically executed.

## Executing Scripts for a Specific Session <a href="#executing-scripts-for-a-specific-session" id="executing-scripts-for-a-specific-session"></a>

You can execute initialization scripts for a specific session

As an example, let's say that you have a script, **myScript1.sc**, with the following contents:

```
echo 'def foo = 42' > scripts/myScript1.sc
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

Start Ocular using `sl ocular`, load your CPG, and use the `runScript` command:

```
cpg.runScript("scripts/myScript1.sc")
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

You'll see the following responses as Ocular runs your script:

```
ocular> foo
res0: Int = 42
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

## Executing Scripts for all Sessions <a href="#executing-scripts-for-all-sessions" id="executing-scripts-for-all-sessions"></a>

To execute initialization code every time you start Ocular, write it to a **.sc** file in your **\~/.shiftleft/ocular** directory. We recommend calling your file **predef.sc**, but by default, Ocular executes all of the files with the **.sc** extension in that directory whenever it starts.

As an example, let's say that you've created your **predef.sc** file as follows:

```
echo 'def foo = 42' > ~/.shiftleft/ocular/predef.sc
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

Start Ocular using `sl ocular`. You'll see the results of the file having been run:

```
ocular> foo
res0: Int = 42
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)
