You are not logged in.
i recently discover dtach, i use screen a lot, and someone give me this .bashrc function to make easyer the use of it, so i want to make a similar one for dtach so i can see detached sessions or autoattach it if detached or create them
### Screen Function Mirror in terminal :: scr ###
function scr {
case $TERM in
xterm*|rxvt*)
if screen -ls | grep -q Main; then
screen -xr Main
else
screen -S Main
fi
;;
esac
}
i made this one for dtach but not acomplish what i want
### dtach function ###
function detach {
if ls /tmp | grep $1 ;then
dtach -c /tmp/$1.dtach $1
else
dtach -a /tmp/$1.dtach
fi
}
but when i use it i get:
[aleyscha@aleyscha 5 ~]$ ls /tmp | grep dtach
mc.dtach=
[aleyscha@aleyscha 6 ~]$ detach mc
mc-aleyscha/
mc.dtach=
dtach: /tmp/mc.dtach: Address already in use
[aleyscha@aleyscha 7 ~]$
Last edited by leo2501 (2008-10-18 17:41:23)
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
You mixed up the true and false parts, I think.
If it exists you want to attach to it, not create it.
Anyway using ls is troublesome as you can see by the other results. Try this:
if [ -S /tmp/$1.dtach ]; then
dtach -a /tmp/$1.dtach
else
dtach -c /tmp/$1.dtach $1
fi
edit: not -f of course, but -S
Last edited by Procyon (2008-10-18 18:19:47)
Offline
Thankyou Procyon! now it works perfect!
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
Small warning. I spent a good amount of time making myself a script that extensively used dtach to manage all my terminals - then discovered that I couldn't start up applications in the background when these new dtach-managed terminals were open
"app &" worked just fine, but then closing the terminal didn't. "exit" (or in my case, "x") left me with a dead terminal, and after I closed it I had to then figure out which copy of dtach and bash don't have a controlling terminal around them anymore and what their PIDs were, so I could force-kill them too.
-dav7
Last edited by dav7 (2008-10-19 04:35:02)
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
I think dtach has this functionality built in... You're trying to open a process or attach to it if it already exists right?
dtach -A processfile command
Offline
I think dtach has this functionality built in... You're trying to open a process or attach to it if it already exists right?
dtach -A processfile command
yes i know, but im lazy and like those great bash functions to do anything with one command
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline