sudo nano ~/temp_monitor.pyPaste your script content and save the file.
sudo chmod +x ~/temp_monitor.pyTest run (will run once; stop with Ctrl+C):
python3 ~/temp_monitor.pysudo nano /etc/systemd/system/temp-monitor.servicePaste the following service configuration (❗replace REPLACE_WITH_YOUR_USERNAME in 3 places):
[Unit]
Description=Raspberry Pi Temperature Monitor
After=network.target
[Service]
Type=simple
User=REPLACE_WITH_YOUR_USERNAME
WorkingDirectory=/home/REPLACE_WITH_YOUR_USERNAME
ExecStart=/usr/bin/python3 /home/REPLACE_WITH_YOUR_USERNAME/temp_monitor.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable temp-monitor.service
sudo systemctl start temp-monitor.servicesudo systemctl status temp-monitor.service✅ Note:
The CSV files will now be created in:
/home/REPLACE_WITH_YOUR_USERNAME/temp_logs/