# xsession startup scripts

**URL:** <https://community.unix.com/t/xsession-startup-scripts/290217>\
**Category:** UNIX for Advanced & Expert Users\
**Created:** [June 21, 2011, 9:49pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217 "2011-06-21T21:49:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cokedude](https://community.unix.com/letter_avatar/cokedude/32/6_22734026db12803ebb3e059622ac3534.png) [@cokedude](https://community.unix.com/u/cokedude)\
**Post date:** [June 21, 2011, 9:49pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217/1 "2011-06-21T21:49:23Z")

</div>

Can someone please tell me how to run xsession startup scripts whenever I start or after I restart my X session? I'm not trying to do anything fancy I just want this to run. This makes life a lot easier when I use a dual monitor.

```nohighlight
xrandr --output VGA1 --mode 1024x768 --rate 60

```

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [June 21, 2011, 10:56pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217/2 "2011-06-21T22:56:48Z")

</div>

What's your window manager, if any?

---

<div class="post-metadata">

**Author:** ![cokedude](https://community.unix.com/letter_avatar/cokedude/32/6_22734026db12803ebb3e059622ac3534.png) [@cokedude](https://community.unix.com/u/cokedude)\
**Post date:** [June 22, 2011, 4:17pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217/3 "2011-06-22T16:17:16Z")

</div>

I have both kde and gnome. Kde is my default one though.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [June 22, 2011, 4:27pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217/4 "2011-06-22T16:27:19Z")

</div>

KDE has [autostart](http://docs.kde.org/stable/en/kdebase-workspace/kcontrol/autostart/autostart.pdf).

---

<div class="post-metadata">

**Author:** ![cokedude](https://community.unix.com/letter_avatar/cokedude/32/6_22734026db12803ebb3e059622ac3534.png) [@cokedude](https://community.unix.com/u/cokedude)\
**Post date:** [June 22, 2011, 5:32pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217/5 "2011-06-22T17:32:11Z")

</div>

> [@corona688](#):
>
> KDE has [autostart](http://docs.kde.org/stable/en/kdebase-workspace/kcontrol/autostart/autostart.pdf).

What about when I am not using the gui? Or if I want to use a system wide startup script? I don't always use the gui and I would like to create a few scripts that effect the whole system.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [June 22, 2011, 5:39pm UTC](https://community.unix.com/t/xsession-startup-scripts/290217/6 "2011-06-22T17:39:28Z")

</div>

xrandr isn't going to do much when X isn't running.

You can try ~/.xinitrc, though I think some WM's ignore that these days. There might be a global equivalent of it under /usr/X11 somewhere though many X11 files aren't where they used to be these days.

As for general-purpose scripts to run on startup, see if your system has /etc/local.start or /etc/conf.d/local.start.

You can also put a line in a user crontab like `@reboot /path/to/script.sh` and cron will run it on poweron.

---

<div class="post-metadata">

**Author:** ![hnrz](https://community.unix.com/letter_avatar/hnrz/32/6_22734026db12803ebb3e059622ac3534.png) [@hnrz](https://community.unix.com/u/hnrz)\
**Post date:** [June 24, 2011, 3:50am UTC](https://community.unix.com/t/xsession-startup-scripts/290217/7 "2011-06-24T03:50:14Z")

</div>

If X is being started from the console then usually startx is used which is a frontend to xinit which reads the system xinitrc and the user ~/.xinitrc. If using a graphical login manager this file is ignored. If using xdm, then usually it will read the system wide xsession and the user's ~/.xsession. The ~/.xsession file can simply be a symbolic link to ~/.xinitrc. If using another graphical login manager such as GDM or KDM, then the xsession file may not be read and the facilities provided by those login managers and the desktop environment or window manager must be used instead. I usually create a ~/.xinitrc and symlink it to ~/.xsession. If I then use a login manager that does not use ~/.xsession I use its autostart facilities at point it at it.

---

<div class="post-metadata">

**Author:** ![cokedude](https://community.unix.com/letter_avatar/cokedude/32/6_22734026db12803ebb3e059622ac3534.png) [@cokedude](https://community.unix.com/u/cokedude)\
**Post date:** [July 10, 2011, 8:00am UTC](https://community.unix.com/t/xsession-startup-scripts/290217/8 "2011-07-10T08:00:02Z")

</div>

> [@corona688](#):
>
> xrandr isn't going to do much when X isn't running.
> 
> You can try ~/.xinitrc, though I think some WM's ignore that these days. There might be a global equivalent of it under /usr/X11 somewhere though many X11 files aren't where they used to be these days.
> 
> As for general-purpose scripts to run on startup, see if your system has /etc/local.start or /etc/conf.d/local.start.
> 
> You can also put a line in a user crontab like `@reboot /path/to/script.sh` and cron will run it on poweron.

I do not have /etc/local.start or /etc/conf.d/local.start.

I already added my script to ~/.xinitrc with no luck.

Would this work? Would I need to add \* in front of @reboot?

```plaintext
# m h dom mon dow command 
#44 4 27 5 4 /home/bob/Desktop/test
#* * * * * /home/bob/Desktop/yo
#0 * * * * echo hi >> /home/bob/Desktop/come
0 0 * * * /home/bob/Desktop/video
0 * * * * date >> /home/bob/.bash_history
#*/10 0-8 * * * /home/bob/Desktop/logout 
@reboot /home/bob/.xprofile

```

> [@hnrz](#):
>
> I usually create a ~/.xinitrc and symlink it to ~/.xsession. If I then use a login manager that does not use ~/.xsession I use its autostart facilities at point it at it.

What if I don't have a ~/.xsession?
