Let's say I used raspi-config to set my raspberry pi to auto-login to the 'pi' user. How would I have something run after login? My desired effect is that I plug in the pi, and without giving it any input, it boots to a desktop and then runs a shell script. I don't want the script to run before the auto-login - so I wouldn't want to put it in /etc/init.d
Asked
Active
Viewed 1.8k times
1
Jacobm001
- 11,898
- 7
- 46
- 56
Charles Noon
- 113
- 1
- 1
- 4
-
Do you want the script to run on boot, or login? These are different things. – Jacobm001 Mar 16 '16 at 15:15
-
after the autologin - sorry if that wasn't clear – Charles Noon Mar 18 '16 at 19:33
-
This answer works for me. I had to create the autostart directory as it wasn't present in Raspbian Jessie. – Wim Ombelets Apr 14 '16 at 17:22
2 Answers
2
Add this:
@reboot /path/to/python action.py
in your crontab. So, whenever you start your PI, it will automatically call your python script. Plus, this cron job should belong to your same pi user which is auto login in, otherwise it won't get called.
Gaurav Dave
- 200
- 1
- 2
- 15
-
Yes, I've tried this, and it works. Thank you! You may want to change 'restart' to 'reboot' in your answer, though, as that is the actual command. Also, I don't know if this will apply to other cases, but I had to do
sudo crontab -eand have the root crontab run my script. – Charles Noon Apr 04 '16 at 04:14 -
0
-
1
.bashrcis a poor choice as it will be run every time the user opens a terminal window. – Jacobm001 Mar 16 '16 at 15:15 -
So you are saying he meant the first login in his title? bashrc is s login script so I took his title literally. – PaulF8080 Mar 16 '16 at 16:39
-
1
.bashrcis not just a login script. It runs every time bash is started. It sounds like the OP wants a script to run when the machine starts, and then logs in..bashrcwill run every time the bash interpreter is started. Which means it's happening a lot more often than when the user logs in. – Jacobm001 Mar 16 '16 at 16:40 -
When you open a terminal you logon to the terminal. I got docked 2 points because you don't know what a login script is. Haven't you ever seen the messages where user x logs onto TTY a and TTY b etc. – PaulF8080 Mar 16 '16 at 17:27
-
The user is asking about a desktop interface.
.bashrcwill run whenever a bash prompt is started. It's fundamnetally different than what the user asked for. https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29#When_started_as_an_interactive_login_shell – Jacobm001 Mar 16 '16 at 18:04 -
Yeah, this isn't really what I'm looking for. This would only run after I started a terminal emulator, if I booted to desktop. Thanks for the suggestion, though! – Charles Noon Mar 18 '16 at 19:36
-