I have a shell script as follows
#!/bin/bash
USER=someuser
HOSTNAMEORIP=somehostname
SCRIPT="/etc/rc.d/netif restart && /etc/rc.d/routing restart"
su -c "ssh -l ${USER} ${HOSTNAMEORIP} ${SCRIPT}" -s /bin/sh someotheruser
If I login to the machine and just run the "/etc/rc.d/netif restart && /etc/rc.d/routing restart" it works. But if i run the entire script above, i get sh: 1: /etc/rc.d/routing: not found as if it's not handling the script part the same. I can even use the above script without a user like this
#!/bin/bash
USER=someuser
HOSTNAMEORIP=somehostname
SCRIPT="/etc/rc.d/netif restart && /etc/rc.d/routing restart"
ssh -l ${USER} ${HOSTNAMEORIP} ${SCRIPT}
And it works but I need to use su -c <command> -s /bin/sh user because another application is calling the script and the user associated is the only one with ssh-key login/no password to the other machine.
How can i make su -c "ssh -l ${USER} ${HOSTNAMEORIP} ${SCRIPT}" -s /bin/sh someotheruser run the script properly in this use case?
/etc/rc.d/routing restarton the calling machine rather than the machine you are sshing to. Try separatingSCRIPTinto two commands rather than together.su -c "ssh -l ${USER} ${HOSTNAMEORIP} ${SCRIPT1}" -s /bin/sh someotherusersu -c "ssh -l ${USER} ${HOSTNAMEORIP} ${SCRIPT2}" -s /bin/sh someotheruser