How 2 run same command across all open terminals | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How 2 run same command across all open terminals

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-09-2011
mirni mirni is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 2 October 2014, 3:08 AM EDT
Posts: 686
Thanks: 51
Thanked 178 Times in 171 Posts
How 2 run same command across all open terminals

Hi folks. This has been bothering me for a while.

Among the 8 virtual desktops I'm using, I have 18 terminals open right now.

I change some of my user configuration (e.g. put a new alias into ~/.bashrc); but in order to use this new added alias, I have to source the config file:

Code:
. ~/.bashrc

That's all good, but the sourcing stays local to the current terminal. Is there a way to source my .bashrc on ALL open terminals, so that I can use it from any one of them?

I know I can echo into any terminal

Code:
echo Hello > /dev/pts/15

But is there a way to run a command like this?
Something like

Code:
$ echo . ~/.basrhc | /dev/pts/15
bash: /dev/pts/15: Permission denied
bash: echo: write error: Broken pipe

I'm running bash on CentOS box.
Thank you!
Sponsored Links
    #2  
Old 05-09-2011
pflynn pflynn is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 21 August 2012, 9:51 PM EDT
Posts: 65
Thanks: 1
Thanked 14 Times in 12 Posts
It seems that every shell you run is a login shell. Bash reads and executes the ~/.bashrc file only if it is started as an interactive, but not login shell. When Bash starts as an interactive login shell, it reads and executes the ~/.bash_profile file. What you could do is to source the ~/.bashrc file from the ~/.bash_profile file. Something like this:

# .bash_profile
# sourcing .bashrc:

. ~/.bashrc

this way every interactive shell you start will read and execute the ~/.bashrc file, be it a loging shell or not.
Sponsored Links
    #3  
Old 05-09-2011
mirni mirni is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 2 October 2014, 3:08 AM EDT
Posts: 686
Thanks: 51
Thanked 178 Times in 171 Posts
Thanks for the response.
But that is not my problem. I'd like to source the config file (.bashrc, .bash_profile, .myConfigFile, etc.) across all terminals that are already running. So that I don't have to close them, and restart (and lose history, kill programs tied to them etc.)
    #4  
Old 05-09-2011
agama agama is offline Forum Advisor  
Always Learning
 
Join Date: Jul 2010
Last Activity: 7 April 2014, 3:02 PM EDT
Location: earth>US>UTC-5
Posts: 1,466
Thanks: 110
Thanked 506 Times in 485 Posts
To my knowledge you'll have to manually source the rc file in each running instance of the shell.

If you want to be clever, and anticipate doing this often enough, you could put the following command into your .bashrc file:


Code:
trap ". $HOME/.bashrc" 16

Once that is set in a running instance of bash, you then only need to send a SIGUSR1 (16) to the process and it will resource the .bashrc file. You could write a small script that susses out all of your running login/interactive shells and executes the necessary kill -16 command. You could pick another signal, but this seems just fine for this case.

Hope this helps some.

Last edited by agama; 05-09-2011 at 10:46 PM.. Reason: typo
The Following 2 Users Say Thank You to agama For This Useful Post:
mirni (05-10-2011), rbatte1 (05-10-2011)
Sponsored Links
    #5  
Old 05-10-2011
mirni mirni is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 2 October 2014, 3:08 AM EDT
Posts: 686
Thanks: 51
Thanked 178 Times in 171 Posts
Thanks agama,

That's a slick solution there with SIGUSR1, that can be certainly put to use.

I also have had the feeling it cannot be done straightforward.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to open multiple virtual terminals to a single LPAR wingcross AIX 1 02-22-2011 10:14 AM
The "PS" command was displaying*terminals named as "SYSCON" kiranjose85 UNIX for Advanced & Expert Users 1 11-28-2008 06:53 AM
one command for all unix terminals rgmekala UNIX for Advanced & Expert Users 5 05-09-2006 10:25 AM
what is the command to connect to remote terminals sendtorohitgupt UNIX for Dummies Questions & Answers 1 05-10-2005 02:08 PM
view all others terminals vkandati UNIX for Dummies Questions & Answers 2 03-08-2005 06:27 PM



All times are GMT -4. The time now is 11:58 PM.