I want to open terminal sessions that are pre popu

2019-09-15 11:40发布

问题:

When I log onto my assorted PCs I usually have a number of things I want to happen automatically, but not always straight away.

These include starting terminal sessions in specific locations on specific desktops (because you get used to using the same layout) and those terminal sessions performing specific acts such as ssh commands. However sometimes when you logon after a reboot you may not want to execute those commands immediately as a higher priority action may need your attention first.

So....what I want is my login script to open terminal sessions and have the session commands pre populated on the command line, but not yet executed.

I use Mate and Compiz as my DE as I like its flexibility.

So in my login script I currently have commands such as.....

mate-terminal --window-with-profile=default  --geometry=85x24+180+400  --title='SSH1' &

mate-terminal --window-with-profile=default  --geometry=85x24+180+1080  --title='VNC1' &

mate-terminal --window-with-profile=default  --geometry=85x24+1305+400  --title='SSH2' &

mate-terminal --window-with-profile=default  --geometry=85x24+1305+1080  --title='VNC2' &

These are dedicated mate-terminal sessions that I then enter a ssh and vnc command respectively to connect to some remote boxes. They always open in the same workspace and as can be seen open at a specific location so I always know exactly where I expect them to be.

However I don't want to use the option to say have the ssh command built into the script (as ssh is time sensitive to the receiver and I may not get to it straight away), instead I want to have the command already pre populated in the terminal session so when I do get to it I don't have to type in the whole command each time.

I had looked at using expect to do this and have that working thus

#!/usr/bin/expect -f

# Get a bash shell
spawn -noecho bash

# wait for a prompt
expect ">:"

# type something
send "ssh root@192.168.1.1"

# Hand over control
interact

exit

however I can't see a way of using expect that allows me to spawn the mate-terminal session at specific geometry locations (possibly I'm missing something obvious as I haven't used expect before).

I also don't want to autologon to the ssh sessions using something like a bash 'mate-terminal -c' option as at times the machine may not be network connected which means I'll have a load of potentially messed up attempted connects.

So in recap.

Bash login script.

Opens mate-terminal session at specific geometry locations with command line pre populated with desired command but not yet executed.

Ideas?