In the below shell script I'm executing the some command cmd remotely where in the command output is redirected to some file cmd_log. I'm getting the desired result as long as the command cmd itself doesn't contain redirection. If in-case the command cmd itself contains redirection, I want the command cmd to be executed in its entirety and cmd_log to be empty
#!/bin/bash
remote_execute() {
cmd=$1
cmd_log=$2
ssh -o StrictHostKeyChecking=no -l user_name 100.100.100.100 "${cmd}" > "${cmd_log}"
}
cmd="echo abc=123 > /a/b/c/abc.txt"
cmd_log="/a/b/c/log.txt"
remote_execute "${cmd}" "${cmd_log}"
Error
./abc.sh: line 13: echo abc=123 > /a/b/c/abc.txt: No such file or directory
Expected Result
abc.txt
abc=123
log.txt to be empty