Micsoftvn
  • 😙Micsoftvn
  • Use Cases
    • For Hacking
      • Kiểm thử mạng
      • Tor - Sock - Proxy
      • Poc
        • POC -draytek-vigor2960 ( CVE-2024-12987 )
    • For Security
      • Security website with htacess file
      • Incident Response
        • Cli AWS - Incident
        • Command line
      • Add basic Authen with Cloudflare
      • Haderning Apache
      • Thiết lập ANTT cho TLS
      • Check network traffic ( Ddos )
      • Tools
        • Tools for AWS
        • Fail2Ban Cheat Sheet
      • Các lỗi thường bảo mật với Websocket
    • For Engineering
      • Thiết lập cấu hình CMD log
      • Cấu hình CLI kết nối đến AWS
      • Sử dụng PET
      • 🔧 Gom Nhóm IP Thành Subnet CIDR Tối Ưu
      • PAC Proxy: Tự Động Cấu Hình Proxy Trong Môi Trường Doanh Nghiệp
      • Sử dụng Podman tạo base images Pentest
      • Tạo YUM Local Repository Trong Container CentOS 7 Sử Dụng Podman
    • For SysAdmin
      • Scripts
        • Bash Script Gen SSH key
        • Health check System
      • Install Oracle Java JDK 18 in Ubuntu 20.04
      • Run script on startup on Ubuntu 22.04
      • Remove Snap from Ubuntu
      • Config Network on Ubuntu Server
      • View Wifi Network Connection
      • Add user can access network interfaces
      • USB drive with QEMU
      • INSTALL AND MANAGE MULTIPLE JAVA JDK AND JRE VERSIONS ON UBUNTU
      • Export Windows Config
      • Auto Install Openvpn
      • Install Nginx Centos 7 or Docker
      • Install Mkdocs
      • Cheat Sheet
        • Cheat sheet Postgres
      • Cài Đặt Fluent Bit Trên Amazon Linux 2023 & Tạo Repository Offline
    • Installations
      • Install Helm on Ubuntu
  • Extras
    • Keyboard Shortcuts
Powered by GitBook
On this page

Was this helpful?

  1. Use Cases
  2. For SysAdmin

Run script on startup on Ubuntu 22.04

First, create a Systemd service file as in an example below. We will store this file as /etc/systemd/system/disk-space-check.service.

[Unit]
After=network.target

[Service]
ExecStart=/usr/local/bin/disk-space-check.sh

[Install]
WantedBy=default.target

After: Instructs systemd on when the script should be run. In our case the script will run after network connection. Other example could be mysql.target etc. ExecStart: This field provides a full path to the actual script to be executed on startup WantedBy: Into what boot target the systemd unit should be installed

Create a script to be executed on Ubuntu system startup. As specified in the above Step 1, the path and the name of the new script in our example will be /usr/local/bin/disk-space-check.sh.

The below is an example of such script:

#!/bin/bash
date > /root/disk_space_report.txt
du -sh /home/ >> /root/disk_space_report.txt

Set appropriate permissions for both, the Systemd service unit and script:

$ sudo chmod 744 /usr/local/bin/disk-space-check.sh 
$ sudo chmod 664 /etc/systemd/system/disk-space-check.service

Next, enable the service unit:

$ sudo systemctl daemon-reload 
$ sudo systemctl enable disk-space-check.service
PreviousInstall Oracle Java JDK 18 in Ubuntu 20.04NextRemove Snap from Ubuntu

Last updated 2 years ago

Was this helpful?