It depends on what is the output of your xrandr when both monitors are connected. If it is for example something like this:
$ xrandr
Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 1400 x 1400
VGA disconnected (normal left inverted right x axis y axis)
LVDS connected 1400x1050+0+0 (normal left inverted right x axis y axis) 286mm x 214mm
1400x1050 60.0*+ 50.0
[...]
Then you can use sed
to get the resolution of your primary monitor (here LVDS) and set that to your secondary monitor (here VGA):
RESOLUTION=$(xrandr | sed -nr 's/LVDS connected ([0-9]+x[0-9]+).*/\1/p')
xrandr --output VGA --mode $RESOLUTION