LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-22-2010, 05:25 PM   #1
Daedagnir
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, 05:53 PM   #2
frieza
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,090

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

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

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

--- rod.
 
Old 12-24-2010, 10:36 AM   #5
Daedagnir
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.
 
  


Reply


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 09:16 AM
Trying to get current cpu percentages in a script for nagios. (bash) helptonewbie Linux - Newbie 3 05-01-2008 06:09 PM
dropline gnome-terminal error: couldnt get a file descriptor referring to the console Randux Slackware 5 12-05-2006 01:55 PM
Referring to current file/path in vim's :!<cmd> jrdioko Linux - Software 1 01-27-2006 04:03 PM
bash scripting - referring to external arguments into loops linsson Linux - General 2 07-23-2004 12:24 PM


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

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