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)
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
Thank you! That's what i was looking for!!