Score:0

How to create a script which runs on startup only by the first boot?

cn flag
Dex

I need a solutions for creating a configuration script which should be executed only by the first boot of the machine. I want to configure new network interfaces through the script with parameters which are inputed by the user. There are various ways to do that. My guess was systemd.

I tried to write a systemd script like this:

[Unit]
Decription=Network Configuration Service

[Service]
Type=simple
ExecStart=/home/configure-network

[Install]
WantedBy=multi-user.target

The systemd service is working fine, but I can't see any outputs of my script on the terminal even if I only use the echo command. What would be the best way to execute my script on startup for the very first time of the system boot. When my system is up and I connect through ssh the script should be executed once and the user should be able to put the parameters sequentially.

My problem is only the execution of the script on boot/startup only once.

vanadium avatar
cn flag
Something escapes me. You want the script to be run only "on first boot" but then refer to the user putting in parameters?
Dex avatar
cn flag
Dex
@vanadium sorry, maybe i dismiss something. So i want to execute a script when i connect through ssh on the machine for the first time. I want to make an image of the os, when this is installed the script is executed and the parameters can be given by user input. My problem is idk how to execute the script on boot or startup or whatever the best way is for my problem.
Dex avatar
cn flag
Dex
@JacobVlijm I don't get it, the script which is executed is irrelevant, i only want to execute it on boot/startup or whatever the best way is. My Problem is that i cant see even nothing, neither the echo. How can i see the lines executed on the terminal to be able to input.
Artur Meinild avatar
vn flag
This existing question details how to run scripts on startup: [How to run scripts on start up?](https://askubuntu.com/questions/814/how-to-run-scripts-on-start-up) Now to this add a method to execute only once. This can be done by creating a file, and only running the script if this file does not exist.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.