You are not logged in.

#1 2012-10-29 20:47:38

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

[SOLVED] Script to launch a tmux session or attach to an existing one

Hi men, i need some help to create a script which could do the following things:
if rtorrent is not running, it starts a new session of rtorrent in tmux, with the command "tmux new -s rtorrent rtorrent" ;
if rtorrent is already running in tmux, it attaches to its session with the command "tmux attach -t rtorrent",
I use the above commands separately, but it would be nice if i could do both things with a script, but i don't know what to do...could you help me, please?

Last edited by TheImmortalPhoenix (2012-10-29 22:16:04)

Offline

#2 2012-10-29 21:30:26

VCoolio
Member
From: Netherlands
Registered: 2010-01-05
Posts: 120

Re: [SOLVED] Script to launch a tmux session or attach to an existing one

Assuming the process name is rtorrent and your tmux commands are correct, you could test if rtorrent is running with [ $(pidof rtorrent) ] and act accordingly:

#!/bin/bash
if [ $(pidof rtorrent) ]; then
    tmux attach -t rtorrent
else
    tmux new -s rtorrent rtorrent
fi

Or a oneliner to make an alias for:

[ $(pidof rtorrent) ] && tmux attach -t rtorrent || tmux new -s rtorrent rtorrent

Offline

#3 2012-10-29 22:15:21

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

Re: [SOLVED] Script to launch a tmux session or attach to an existing one

Thank you! That's what i was looking for!!

Offline

Board footer

Powered by FluxBB