sudo nano ~/temp_monitor.py
Paste your script content and save the file.
sudo chmod +x ~/temp_monitor.py
Test run (will run once; stop with Ctrl+C):
python3 ~/temp_monitor.py
sudo nano /etc/systemd/system/temp-monitor.service
Paste 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.target
sudo systemctl daemon-reload
sudo systemctl enable temp-monitor.service
sudo systemctl start temp-monitor.service
sudo systemctl status temp-monitor.service
✅ Note:
The CSV files will now be created in:
/home/REPLACE_WITH_YOUR_USERNAME/temp_logs/