title: su command in shell script
body: <p>I have a script which copies a file, then untar and install it (agent-service) on multiple systems (IPs are read from systems.txt file). In the script, I wanted to start the agent-service as user "test". However after the script execution, when I check the target system, the agent-service is shown as running as "root" user. What could be wrong here? Am I not using su command correct within the script?</p>
  
  <pre><code>~]# ps -ef | grep agent-service
  
      root     23511 15196  0 02:12 pts/3    00:00:00 agent-service
  </code></pre>
  
  <p>Script> </p>
  
  <pre><code>#!/bin/bash
  export AGENT=linux-5.8.1.tar.gz
  
  while read host; do
  
  scp $AGENT root@$host:/opt
  
  
  ssh -n root@$host 'cd /opt/linux;
  tar zxvf linux-5.8.1.tar.gz;
  mkdir /opt/hyperic;
  useradd -m test;
  chown -R test:test /opt/linux;
  su - test;
  /opt/linux/agent-service start'
  
  done &lt; systems.txt
  </code></pre>