RLD831
Posts: 2
Joined: Sun Aug 18, 2019 4:48 am

Deleted Fan Script Tries to Run on Login

Sun Aug 18, 2019 4:58 am

A while back I installed a fan in my Raspberry Pi 4 running Raspbian. I used a python script to let it run at variable speeds. I recently decided to just power it off of the 3.3V line, so I don't need the circuit or the script. Now every time I log in with SSH, I get the following error

Code: Select all

python: can't open file '/home/pi/fan_ctrl.py': [Errno 2] No such file or directory
Obviously, it is looking for fan_ctrl.py in the home directory, which has already been deleted. I'm wondering if there is a specific file that I can edit to prevent it from trying to run, or if there is a way to search for the file that is trying to run that python script so I can edit it.

I don't remember which file I changed when I originally did it, and I'm just getting into Linux with Linux Mint and this Raspberry Pi, so any help is appreciated.

User avatar
thagrol
Posts: 1782
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Deleted Fan Script Tries to Run on Login

Sun Aug 18, 2019 7:18 pm

Given that you're seeing it at every login, start with .profile and .bashrc in your home directory. If there's nothing there try the system wide equivalents: /etc/profile and /etc/bashrc

Edit:

You could just try this:

Code: Select all

cd ~
grep -i fan_ctrl.py .*
This space unintentionally left blank.

User avatar
DougieLawson
Posts: 35840
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Deleted Fan Script Tries to Run on Login

Sun Aug 18, 2019 8:28 pm

Try creating /home/pi/fan_ctrl.py (as a bash script that logs who called it)

Code: Select all

#!/bin/bash
PARENT_COMMAND=$(ps -o comm= $PPID)
logger fan_ctrl.py called from $PARENT_COMMAND 
chmod 755 /home/pi/fan_ctrl.py

That should get something like

Code: Select all

Aug 18 21:26:34 raspberrypi root: fan_ctrl.py called from systemd
in /var/log/syslog which may give a clue as to who called your script.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

bls
Posts: 211
Joined: Mon Oct 22, 2018 11:25 pm

Re: Deleted Fan Script Tries to Run on Login

Sun Aug 18, 2019 8:59 pm

You could also try to search for it:

Code: Select all

sudo find / -exec grep -H fan_ctrl \{\} \; | less
This will search through every file on your SD card for it. There will probably be some errors, but once the search is complete, only the valid results will remain in less.

RLD831
Posts: 2
Joined: Sun Aug 18, 2019 4:48 am

Re: Deleted Fan Script Tries to Run on Login

Mon Aug 19, 2019 4:12 pm

Thank you for all of the different methods to try. It ended up being a line added to /etc/profile.

User avatar
thagrol
Posts: 1782
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Deleted Fan Script Tries to Run on Login

Mon Aug 19, 2019 7:57 pm

RLD831 wrote:
Mon Aug 19, 2019 4:12 pm
Thank you for all of the different methods to try. It ended up being a line added to /etc/profile.
For future reference, that's a really bad place to have put it.

That (and anything it calls) gets run at evey login of every user so you quickly end up with multipe copies running. And stuff there will get killed on logut. So if you have three users logged in (or the same user loggedin three times) you'll have three copies running.

it's the right place for some things but for stuff you want run once at boot time use one of cron, a systemd service or /etc/rc.local.

For suf you want to run whenever a particular user logs in use that user's crontab, their .profile (/home/user/.profile), or their .bashrc (/home/user/.bashrc).
This space unintentionally left blank.

Return to “Troubleshooting”