I have a crontab which launches tmux-launching-script as follows :

-sh-3.00# crontab -l
@reboot /root/scripts/tmux_autostart.sh


# setup tmux session

tmux new -d -s my_session

but when the system boots I don't have my regular prompt but shell prompt :


how to change it to bash if I already have this in my config .tmux.conf

set-option -g default-shell /bin/bash


-sh-3.00# cat /etc/crontab

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

Your @reboot job is in root's crontab. The variables set in a crontab only apply in this crontab, so the settings in /etc/crontab have no influence on the job executed by root's crontab.

The default shell in Cron is /bin/sh, and the SHELL environment variable is set to /bin/sh unless overridden. So Tmux starts with SHELL=/bin/sh.

It appears that your /bin/sh is Bash 3.00. The prompt indicates that bash was started as a login shell, and that no initialization file set PS1 (there was probably no initialization file at all).

If you set default-shell in ~/.tmux.conf, this takes precedence over the SHELL environment variable. I suspect you aren't showing .tmux.conf in root's home directory but in some other location, maybe your own home directory.

You have a choice of setting SHELL=/bin/bash in root's crontab, or writing a .tmux.conf file in root's home directory.



Instead of doing this as a @reboot, what if you restructured things slightly so that it was say every few minutes, and did a check to see if tmux was already running, if not, then call your tmux_autostart.sh.


Every 5 minutes run to see if tmux_autostart.sh is running. For starters a test like this will see if tmux_autostart.sh is up:

# down
$ ps -eaf|grep -q "[t]mux_autostart.sh"
$ echo $?

# up
$ ps -eaf|grep -q "[t]mux_autostart.sh"
$ echo $?

We can then use this above test like so in our cron:

*/5 * * * *  ps -eaf|grep -q "[t]mux_autostart.sh" && /root/scripts/tmux_autostart.sh


If you're only interested in starting this up when you login I believe you could put your script in the file $HOME/.xintrc. Then it will run when you login.

  • Besides running a crontab every few minutes being a horrible way to run something at boot time (why do I sometimes not find my tmux session when I log in shortly after boot? Why is my disk waking up every 5 minutes?), how is it supposed to help? Whether it's */5 * * * * or @reboot doesn't change the value of SHELL or HOME. – Gilles 'SO- stop being evil' Jun 7 '13 at 0:38
  • @Gilles - is it a optimal solution? Of course not, but so what if something like a ps | grep runs every five minutes. Modern day systems can "handle" it. Also the OP shows crontab -l, which I see has a hash prompt #, so maybe it's root, but my experience says a crontab -l is typically a user's crontab entry. In those I would expect them to run as the user so I would expect the SHELL and HOME to be set for them then. – slm Jun 7 '13 at 4:47
  • My point is that it doesn't matter when the crontab entry runs anyway, changing from @reboot to a time won't fix his problem. You're working around something that isn't a problem (the use of @crontab) without tackling the real problem (SHELL not set to the expected value, presumably because it's set in /etc/crontab and Patryk expected it to also take efect in user crontabs). – Gilles 'SO- stop being evil' Jun 7 '13 at 7:37

I think there is one way to do it by using such a cronjob:

@reboot . $HOME/profile; /root/scripts/tmux_autostart.sh

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.