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

  • 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

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.

| improve this answer | |
  • 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 -e and have the root crontab run my script. – Charles Noon Apr 4 '16 at 4:14
  • @CharlesNoon edited my answer. – Gaurav Dave Apr 4 '16 at 4:50

~/.bashrc is the common way, I guess.

| improve this answer | |
  • 1
    .bashrc is 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
    .bashrc is 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. .bashrc will 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. .bashrc will run whenever a bash prompt is started. It's fundamnetally different than what the user asked for. en.wikipedia.org/wiki/… – Jacobm001 Mar 16 '16 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.