This is my command that I have in my script:ssh -i $KEY $USER@$HOST sudo su tom; echo $DATA >> /home/user/file.txtThese commands work fine on there own but together in the script it just hangs.If you run this command by itself sudo su tom; cat /home/user/file.txtIt will only execute cat when you logout of the user tom.How do you change user and execute a command in a bash script ?
ssh change user and execute command
bash;ssh
I was unable to switch users, executing as root seemed to do the trick.ssh -i $KEY $USER@$HOST echo $DATA |sudo tee $DIRECTORY