Skip to content

Commit 1e51b88

Browse files
committed
docs(srv): update
1 parent 1306947 commit 1e51b88

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

pages/serverless-jobs/how-to/execute-complex-commands.mdx

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: How to execute complex commands using Serverless Jobs
3-
description: Learn how to run complex commands and scripts using Scaleway Serverless Jobs and Secrets Manager.
2+
title: How to execute complex startup commands using Serverless Jobs
3+
description: Learn how to run complex commands at job run start and scripts using Scaleway Serverless Jobs and Secrets Manager.
44
tags: run execute start serverless job scaleway script startup secret bash complex command pipe
55
dates:
66
validation: 2025-08-19
@@ -27,6 +27,9 @@ You can bypass this limitation by passing complex commands and scripts to a Serv
2727
3. Click **+ Create secret**.
2828

2929
4. Select **Import secret**, choose the **Opaque** secret type, then drag and drop your file to the dedicated area. The maximum file size for your secret is 64 KiB.
30+
<Message type="note">
31+
We recommend using a shell script (`.sh`) file containing your command. Refer to the [section below](#complex-commands-examples) for example commands.
32+
</Message>
3033

3134
5. Choose the **Scaleway-managed encryption key**, as it requires no configuration on your side.
3235

@@ -38,4 +41,74 @@ You can bypass this limitation by passing complex commands and scripts to a Serv
3841

3942
Your file can now be passed to your Serverless Job as a secret reference.
4043

41-
##
44+
## Create a Serverles Job referencing your command as a secret
45+
46+
1. Click **Jobs** in the **Serverless** section of the side menu. The jobs page displays.
47+
48+
2. Click **Create job**. The job creation wizard displays.
49+
50+
3. Select the **external** container registry.
51+
52+
4. Enter the following image URL:
53+
```sh
54+
scaleway/cli:latest
55+
```
56+
57+
5. Enter a name, select the desired region, and choose the smallest **resources** available.
58+
59+
6. Enter a CRON schedule to run your job periodically. Refer to the [dedicated documentation](/serverless-jobs/reference-content/cron-schedules/) on CRON schedules.
60+
61+
7. Add your command file as a [secrets reference](/serverless-functions/concepts/#secrets). Refer to the [dedicated documentation] on secrets for more information.
62+
63+
8. Add the following startup command to call your file:
64+
```sh
65+
bash /complex_command.sh start
66+
```
67+
68+
9. Click **Create job** to finish.
69+
70+
You job is now ready to run at the specified schedule.
71+
72+
## Complex commands examples
73+
74+
Below are examples of commands that must be passed via a secret referenced as a file in Serverless Jobs. You can find more complex commands examples on the [Scaleway CLI repository](/https://github.com/scaleway/scaleway-cli/blob/master/docs/cookbook.md).
75+
76+
**Retrieve a specific field from the output using jq**
77+
78+
```bash
79+
## Retrieve all available instance type names
80+
81+
# Using jq
82+
scw -o json instance server-type list | jq -r '.[].name'
83+
# Using CLI templates
84+
scw instance server-type list -o template="{{ .Name }}"
85+
```
86+
87+
**Filter command output using jq**
88+
89+
```bash
90+
# Retrieve all available instance type with GPUs
91+
scw -o json instance server-type list | jq '.[] | select (.gpu > 0)'```
92+
```
93+
94+
**Parallelize actions using xargs**
95+
96+
```bash
97+
## Reboot all listed servers at the same time, 8 max concurrent actions
98+
99+
# Using jq
100+
scw -o json instance server list | jq -r '.[].id' | xargs -L1 -P8 scw instance server reboot
101+
# Using CLI templates
102+
scw instance server list -o template="{{ .ID }}" | xargs -L1 -P8 scw instance server reboot
103+
```
104+
105+
**Create arguments for a CLI command and use it in xargs**
106+
107+
```bash
108+
## List private-nics of all listed servers
109+
110+
# Using jq
111+
scw -o json instance server list | jq -r '.[] | "server-id=\(.id)"' | xargs -L1 scw instance private-nic list
112+
# Using CLI templates
113+
scw instance server list -o template="server-id={{ .ID }}" | xargs -L1 scw instance private-nic list
114+
```

0 commit comments

Comments
 (0)