What I finally did as a workaround is, instead of doing this tmux commands 
in a cronjob, adding them to the ~/.bashrc file. 
So every time a terminal is opened (whether is a screen (tty) or through 
ssh (pts)) if the tmux session doesn´t exist, it creates it. This way there 
is always this session available as soon as a terminal is opened. The added 
commands are:

/usr/bin/tmux has-session -t smartbox 2>/dev/null
$SESSION= sessionname
if [ "$?" -eq 1 ] ; then
    /usr/bin/tmux new-session -s $SESSION -d -x
   #whatever format/commands you want your session to have by default, ex:
    /usr/bin/tmux split-window -t $SESSION  -v
fi



El jueves, 13 de enero de 2022 a las 17:37:11 UTC+1, [email protected] 
escribió:

>
> /dev/pts/0 being in use will make no difference.
>
> You put this in root's crontab, so tmux will be running as root, is that 
> what you intend?
>
> If so and you still cannot attach as root, then likely your script is 
> failing for some other reason so you will need to debug it.
>
> Does the script work if you run it manually?
>
> What if you run it from cron like this:
>
>     /bin/bash -x /path/to/script 2>/tmp/log
>
> Does /tmp/log show errors? You may want to add "|| exit 1" to all the 
> commands to work out which one it stops at.
>
>
>
>
> On Thu, 13 Jan 2022 at 15:20, Gabriel Lupini <[email protected]> wrote:
>
>> Hi guys,
>>
>> We've been trying to make a cronjob to create a new session of tmux after 
>> reboot, so later after an ssh connection or directly with a screen located 
>> in /dev/tty1 we can attach the shown terminal to the already made session. 
>>
>> After making a simple .sh to do so in "sudo crontab -e":
>> @reboot /bin/bash /home/USER/start.sh
>>
>> With start.sh as
>> #!/bin/bash
>> /bin/sleep 5
>> source /home/debian/.bashrc
>> /usr/bin/tmux new-session -d -s session1
>> /usr/bin/tmux send-keys -t session1 "source /home/USER/.bashrc" C-m
>> /usr/bin/tmux send-keys -t session1 "echo \"hello\"" C-m
>>
>> After connecting via ssh and doing "tmux attach-session -t session1" in 
>> that terminal we get the message "no sessions"
>>
>> The opened terminal tty is "/dev/pts/1" when I run this script so I 
>> assume the usual "/dev/pts/0" is being occupied during the cronjob, but we 
>> find ourselves unable to access it. Any idea of what we are doing wrong?
>>
>> Any help would be appreciated, Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "tmux-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web, visit 
>> https://groups.google.com/d/msgid/tmux-users/60a26273-02f3-4f9d-a460-a9f3c63b6634n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/tmux-users/60a26273-02f3-4f9d-a460-a9f3c63b6634n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/tmux-users/19ef1d1a-2f23-41f0-8bbd-e1d271ab4d8dn%40googlegroups.com.

Reply via email to