Run a script at startup as a user

5,373

You can faff about with an elaborate sudo command in /etc/rc.local, but the best way is to use the user's cron table. cron has some nifty scheduling keywords including @reboot which will run the defined script or command when the system is rebooted.

So, as that user, run crontab -e, and add this line to the file:

@reboot screen -dmS ScreenName /path/to/your/script.sh
Share:
5,373

Related videos on Youtube

Tundral
Author by

Tundral

Updated on September 18, 2022

Comments

  • Tundral
    Tundral over 1 year

    Is there a way to run a script on startup as a user on Debian 7? My script is

    screen -dmS name ./script.sh
    

    So essentially I want to run a script on startup that would make a screen window and run a script in it

  • Tundral
    Tundral over 7 years
    No it's a server actually
  • Rob
    Rob over 7 years
    Then what do you mean by screen window? That was suggesting to me a window environment. Did you mean a process that starts when the server boots up?
  • Tundral
    Tundral over 7 years
    Is session the right term then. I want it to make a screen session which I can attach to later if I need to. All this will be done through SSH
  • Rob
    Rob over 7 years
    Ok then add it to you .profile in your home it gets sourced every time you open a terminal be it on the box or through ssh.