I have a bash script for copying two files from a remote machine (that I cannot control), stored in a a path that needs root
access. Here it is:
ssh administrator@host "mkdir ${DIR}"
ssh -t administrator@host "sudo su - root -c 'cp /path/for-root-only/data1/${FILENAME} ${DIR}/'"
ssh administrator@host "mv ${DIR}/${FILENAME} ${DIR}/data1-${FILENAME}"
ssh -t administrator@host "sudo su - root -c 'cp /path/for-root-only/data2/${FILENAME} ${DIR}/'"
scp administrator@host:$DIR/{${FILENAME},data1-${FILENAME}} .
ssh administrator@host "rm -r ${DIR}"
The script prompt for the same password a lot of time. I tried to merge all commands through here document like this for ssh -t
:
ssh -t administrator@host << EOF
mkdir ${DIR}
sudo su - root -c 'cp /path/for-root-only/data1/${FILENAME} ${DIR}/'
mv ${DIR}/${FILENAME} ${DIR}/data1-${FILENAME}
sudo su - root -c 'cp /path/for-root-only/data2/${FILENAME} ${DIR}/'
EOF
scp administrator@host:$DIR/{${FILENAME},data1-${FILENAME}} .
ssh administrator@host "rm -r ${DIR}"
but there is this warning:
Pseudo-terminal will not be allocated because stdin is not a terminal.
I would like to ask if there is a proper way to write that script to minimize the number of password prompting
ControlPath
option to use the master connection feature, either on the command line or in the configuration file. Sorry. – Gilles 'SO- stop being evil' Jul 20 '16 at 09:46