Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-22-2010, 06:25 PM   #1
LQ Newbie
Registered: Dec 2010
Location: Colorado, USA
Distribution: Ubuntu 10.04, Ubuntu 10.10, gentoo
Posts: 3

Rep: Reputation: 0
Referring to the Current Terminal in a Bash Script?

Hey all.

Hopefully this is an easy question. I've got some bash scripts that I'm testing which operate on different screen sessions under different usernames. In order to check the status of them, however, I have to attach the screen sessions to my current terminal.

I run into problems, though; I only allow SSH to my machine from one username; the others shouldn't need SSH access. So, I log in as one user, and su into whichever user I need. Without performing a chmod o+rw on the terminal before I su into a different user, screen complains that it can't reattach to my terminal, because the user trying to make it attach doesn't have the permissions to do so.

Seeing as I forget to do this a lot, I wanted to make a script that I'd run on log-in to do this for me. Unfortunately, I don't know if there's a bash variable that refers to the current terminal - I can't always guarantee that I'll be logging in to /dev/pts/0, especially if my internet connection gets cut and I leave a hanging terminal...

Is there a variable for that or a way to refer to it in a script? If not, how do I work around that?

Thanks for any help!

- Dae
Old 12-22-2010, 06:53 PM   #2
Senior Member
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,226

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
perhaps you should try reversing the order of operations and do the su from within screen?
Old 12-22-2010, 07:25 PM   #3
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,238

Rep: Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405
The tty program can tell you which terminal is in use.
Old 12-24-2010, 11:33 AM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Maybe you should use screen in multiuser mode, possibly along with access control lists.

--- rod.
Old 12-24-2010, 11:36 AM   #5
LQ Newbie
Registered: Dec 2010
Location: Colorado, USA
Distribution: Ubuntu 10.04, Ubuntu 10.10, gentoo
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for all the quick replies, everyone; I'll give them a try and see which one works the best.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to make a bash script keep running in same terminal after it calls second script? JohnRock Linux - Newbie 4 06-25-2010 10:16 AM
Trying to get current cpu percentages in a script for nagios. (bash) helptonewbie Linux - Newbie 3 05-01-2008 07:09 PM
dropline gnome-terminal error: couldnt get a file descriptor referring to the console Randux Slackware 5 12-05-2006 02:55 PM
Referring to current file/path in vim's :!<cmd> jrdioko Linux - Software 1 01-27-2006 05:03 PM
bash scripting - referring to external arguments into loops linsson Linux - General 2 07-23-2004 01:24 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration