how to run create file in ubuntu when user login automatically

  • Create a script file, e.g. named my_file.sh, in the /etc/profile.d/ directory.
  • Put #!/bin/bash as the first line.
  • Write whatever command(s) you want to be executed immediately after logging in, e.g. pgrep udhcpd.
  • Mark your file as executable: chmod +x /etc/profile.d/my_file.sh

*It should get executed after login. In case it doesn’t or you don’t have the ability to use root privileges, creating the same file under ~/.config/autostart should work fine (I haven’t tried this directory before).


Leave a Reply