I work on multiple terminal for my task, now i have to manually run refresh commands everyday i start working, I want to create a cron job that runs a script that finds my open terminal and run few commands for me
I tried using script that run spawns a terminal and runs the command but that is solving my problem as i have to open a new terminal and again run some commands
15
IMO it’s easier to poll from all terminals than push from one terminal to all.
- In appropriate rc file (e.g.
.bashrc
,.bash_profile
,.profile
) just start a simple loop that runs once a day. E.g.
while true; do
sleep 86400 # 24 hours
# ... refresh commands ...
done &
- If you want something more on demand, instead of on a fixed schedule
while true; do
sleep 60
if -r /tmp/commands-to-execute.sh; then
echo "running /tmp/commands-to-execute.sh"
bash /tmp/commands-to-execute.sh
fi
done &
Now you can run following whenever you want to run some refresh commands in all your open terminals:
cat << EO_REFRESH_CMDS > /tmp/commands-to-execute.sh
# ... refresh commands ...
EO_REFRESH_CMDS
sleep 50
rm /tmp/commands-to-execute.sh
If you don’t wanna rely on sleep 50
then you can create a /tmp/$$.executed
after executing commands and check for it’s existence to ensure you don’t execute if it’s already executed, and delete /tmp/$$.executed
if it’s older than say an hour or two.
1