简体   繁体   中英

How do I get all my terminals/shells to reload their environment by running a script?

I use my mac at home and at work. And I use a program called Marco-polo to detect whether I am at home or at work. Through this, I can get it to run a script that changes my proxy and run some scripts to configure my computer differently for the different environments like copying hosts.work and hosts.home over /etc/hosts and copy .profile.work and .profile.home over ~/.profile.

What I have not been able to do successfully so far, is to find a way to have all my running terminals reload my .profile file when I change location. Can anyone suggest a method for doing this?

Thanks, Tom


fm48 answer below in combination with this simple script (placed at /usr/bin/pkill) worked perfectly.

#!/bin/sh
sig=""
if [[ "$1" =~ - ]]; then
  sig=$1;
  shift
fi

for X in `ps acx | grep -i $1 | awk {'print $1'}`; do
    kill $sig $X;
done

You should use a signal like SIGUSR1. First enable the signal to reload the ~/.profile with trap ". ${HOME}/.profile" SIGUSR1 .

After that you should send all shells the SIGUSR1 signal. For example pkill -SIGUSR1 bash if bash is the used shell.

如果您将Screen作为终端管理器,则可以使用以下命令向所有shell发送命令:
screen -X at \\# stuff "whatever command\\n"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM