<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic scp by using script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6130795#M495997</link>
    <description>&lt;P&gt;for i in hostname&lt;/P&gt;&lt;P&gt;do&lt;/P&gt;&lt;P&gt;scp -r target files $i:/home/testuser&lt;/P&gt;&lt;P&gt;done&lt;/P&gt;&lt;P&gt;exit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;since i am going to perform scp for 150 servers,i need to redirect logs to a file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need to check if target files is&amp;nbsp; copied to target host.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2013 15:35:26 GMT</pubDate>
    <dc:creator>tempsample</dc:creator>
    <dc:date>2013-07-10T15:35:26Z</dc:date>
    <item>
      <title>scp by using script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6130795#M495997</link>
      <description>&lt;P&gt;for i in hostname&lt;/P&gt;&lt;P&gt;do&lt;/P&gt;&lt;P&gt;scp -r target files $i:/home/testuser&lt;/P&gt;&lt;P&gt;done&lt;/P&gt;&lt;P&gt;exit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;since i am going to perform scp for 150 servers,i need to redirect logs to a file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need to check if target files is&amp;nbsp; copied to target host.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2013 15:35:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6130795#M495997</guid>
      <dc:creator>tempsample</dc:creator>
      <dc:date>2013-07-10T15:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: scp by using script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6130849#M495998</link>
      <description>&lt;P&gt;&amp;gt; since i am going to perform scp for 150 servers,i need to redirect logs to a file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As with most other commands, you can do it with the &amp;gt;, &amp;gt;&amp;gt;, 2&amp;gt; and/or 2&amp;gt;&amp;gt;&amp;nbsp; redirection operators.&lt;/P&gt;&lt;P&gt;The only trick is that you probably should use &amp;gt;&amp;gt;, so the logs of the later scp runs won't overwrite the log file of the previous run, but instead adds to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;for i in hostname
do
    scp -r target files $i:/home/testuser &amp;gt;&amp;gt;statistics.log 2&amp;gt;&amp;gt;errors.log
done
exit&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; i need to check if target files is&amp;nbsp; copied to target host.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The simplest way is to check the exit status of the scp command. "man scp" says it will be 0 if the copy operation is successful, and greater than 0 if not successful.&lt;/P&gt;&lt;P&gt;So:&lt;/P&gt;&lt;PRE&gt;for i in hostname
do
    scp -r target files $i:/home/testuser &amp;gt;&amp;gt;statistics.log 2&amp;gt;&amp;gt;errors.log
    if [ $? -gt 0 ]
    then
        echo "*** Copy to host $i failed ***" &amp;gt;&amp;gt;errors.log
    fi
done
exit&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2013 16:30:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6130849#M495998</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2013-07-10T16:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: scp by using script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6131075#M495999</link>
      <description>&lt;P&gt;&amp;gt;The only trick is that you probably should use &amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can redirect the output of the whole loop and you won't need that "&amp;gt;&amp;gt;":&lt;/P&gt;&lt;P&gt;for i in hostname; do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; scp -r target files $i:/home/testuser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if [ $? -ne 0 ] then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "*** Copy to host $i failed ***" 1&amp;gt;&amp;amp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; fi&lt;/P&gt;&lt;P&gt;done &amp;gt; statistics.log 2&amp;gt; errors.log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Contrary to the man page, your check on $? should really be -ne instead of -gt.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2013 20:45:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scp-by-using-script/m-p/6131075#M495999</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2013-07-10T20:45:58Z</dc:date>
    </item>
  </channel>
</rss>

