<?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 Re: expect script for sftp file transfer. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189344#M461307</link>
    <description>&lt;!--!*#--&gt;&amp;gt; I want to write a expect script [...]&lt;BR /&gt;&lt;BR /&gt;I don't see "expect" anywhere in your script.&lt;BR /&gt;(Which is good, but confusing.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But i don't know how to put the logic to&lt;BR /&gt;&amp;gt; send an e-mail [...]&lt;BR /&gt;&lt;BR /&gt;I'm confused.  Are you asking (again) how to&lt;BR /&gt;send e-mail from a script?  A Forum search&lt;BR /&gt;for keywords like:&lt;BR /&gt;      script send e-mail&lt;BR /&gt;should find many examples, including, for&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1351442" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1351442&lt;/A&gt;</description>
    <pubDate>Fri, 24 Jul 2009 12:42:21 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2009-07-24T12:42:21Z</dc:date>
    <item>
      <title>expect script for sftp file transfer.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189343#M461306</link>
      <description>Hi,&lt;BR /&gt;I want to write a expect script for sftp file transfer.&lt;BR /&gt;I am able to connect the sftp server through expect script. But i don't know how to put the logic to send an e-mail for me when the script runs and how many files send and also if there is problem connecting sftp server should send me an e-mail. I am already having the shell script for sftp but without password.&lt;BR /&gt;&lt;BR /&gt;cd /ABC/EFC/DF/TEST&lt;BR /&gt;file=$(ls)&lt;BR /&gt;for x in $file&lt;BR /&gt;do&lt;BR /&gt;   mv $x $x.txt&lt;BR /&gt;   chown aaaa:bbbb $x&lt;BR /&gt;   chmod 666 $x&lt;BR /&gt;done&lt;BR /&gt;/usr/bin/sftp -b /abc/script/put xxxxxxxx@aaaaa.ssss.co&lt;BR /&gt;RC=$?&lt;BR /&gt;echo " "&lt;BR /&gt;echo "sftp return code is : $RC"&lt;BR /&gt;if test $RC -eq 255&lt;BR /&gt;then&lt;BR /&gt;     echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;BR /&gt;     echo "There is some problem connecting to the sftp server so exiting the script here"&lt;BR /&gt;     echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;BR /&gt;     exit&lt;BR /&gt;elif test $RC -eq 1&lt;BR /&gt;then&lt;BR /&gt;     echo "Looks like there are no files to transfer to the sftp server"&lt;BR /&gt;elif test $RC -eq 0&lt;BR /&gt;then&lt;BR /&gt;     echo "sftp ran OK"&lt;BR /&gt;else&lt;BR /&gt;     echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;BR /&gt;     echo "There was some unknown error occurred during sftp so exiting the script here"&lt;BR /&gt;     echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;BR /&gt;     exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Datestamp=$(date +%Y%m%d%H%M)&lt;BR /&gt;&lt;BR /&gt;file=$(ls)&lt;BR /&gt;N=0&lt;BR /&gt;for x in $file&lt;BR /&gt;do&lt;BR /&gt;    (( N = N + 1 ))&lt;BR /&gt;    echo "Processing the file: $x"&lt;BR /&gt;    mv $x ../old/$x.$Datestamp&lt;BR /&gt;done&lt;BR /&gt;echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;BR /&gt;echo "Number of files transferred to the ftp server are: $N"&lt;BR /&gt;echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"&lt;BR /&gt;&lt;BR /&gt;And in script /abc/script/put &lt;BR /&gt;mput *.txt&lt;BR /&gt;quit&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Narendra</description>
      <pubDate>Fri, 24 Jul 2009 10:00:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189343#M461306</guid>
      <dc:creator>Narendra Uttekar</dc:creator>
      <dc:date>2009-07-24T10:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: expect script for sftp file transfer.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189344#M461307</link>
      <description>&lt;!--!*#--&gt;&amp;gt; I want to write a expect script [...]&lt;BR /&gt;&lt;BR /&gt;I don't see "expect" anywhere in your script.&lt;BR /&gt;(Which is good, but confusing.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But i don't know how to put the logic to&lt;BR /&gt;&amp;gt; send an e-mail [...]&lt;BR /&gt;&lt;BR /&gt;I'm confused.  Are you asking (again) how to&lt;BR /&gt;send e-mail from a script?  A Forum search&lt;BR /&gt;for keywords like:&lt;BR /&gt;      script send e-mail&lt;BR /&gt;should find many examples, including, for&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1351442" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1351442&lt;/A&gt;</description>
      <pubDate>Fri, 24 Jul 2009 12:42:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189344#M461307</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-07-24T12:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: expect script for sftp file transfer.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189345#M461308</link>
      <description>You might want to use Perl with Net::SFTP.&lt;BR /&gt;You can then trap errors in that.&lt;BR /&gt;Otherwise you can try using:&lt;BR /&gt;&lt;BR /&gt;In Expect you should be able to use &lt;BR /&gt;something like this:&lt;BR /&gt;&lt;BR /&gt;expect {&lt;BR /&gt;       "some expected string" { &lt;BR /&gt;                         exec echo "error" | mailx -s "error" &lt;USER&gt;&lt;BR /&gt;                              }&lt;BR /&gt;       {&lt;BR /&gt;&lt;BR /&gt;But I too do not see any expect code.&lt;BR /&gt;Looks like you are just running a shell &lt;BR /&gt;script. In that case just run mailx after&lt;BR /&gt;you determine $RC.&lt;BR /&gt;&lt;BR /&gt;echo "string" | mailx -s "Subject" &lt;USER&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/USER&gt;&lt;/USER&gt;</description>
      <pubDate>Fri, 24 Jul 2009 13:39:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189345#M461308</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2009-07-24T13:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: expect script for sftp file transfer.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189346#M461309</link>
      <description>Try this.. &lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/expect -f&lt;BR /&gt;&lt;BR /&gt;# Customizable things start here&lt;BR /&gt;&lt;BR /&gt;set site "site.domain.tld"&lt;BR /&gt;set user "useraccountname"&lt;BR /&gt;set password "userpassword"&lt;BR /&gt;&lt;BR /&gt;# Timeout, in seconds, when first making the connection&lt;BR /&gt;set inittimeout "15"&lt;BR /&gt;&lt;BR /&gt;# Timeout, in seconds, when actually uploading the file&lt;BR /&gt;set conntimeout "60"&lt;BR /&gt;&lt;BR /&gt;# Location of the nonstandard scp(1) program&lt;BR /&gt;set scpprog "scp"&lt;BR /&gt;&lt;BR /&gt;# Customizable things end here&lt;BR /&gt;# ==============================&lt;BR /&gt;&lt;BR /&gt;# Leave the remote directory as is... &lt;BR /&gt;set remotefile "/incoming"&lt;BR /&gt;&lt;BR /&gt;# Create an incoming directory on your local server. "mkdir /esu3-fs/blr/school_fusion/incoming"&lt;BR /&gt;# Insert or upload all *.csv files in "/esu3-fs/blr/school_fusion/incoming"&lt;BR /&gt;&lt;BR /&gt;set localfile1 "/localfilelocation/filename.csv"&lt;BR /&gt;&lt;BR /&gt;send_user "Uploading $localfile1 to $user@$site:$remotefile ....\n\n"&lt;BR /&gt;&lt;BR /&gt;# launch SCP&lt;BR /&gt;set result [spawn $scpprog $localfile1 $user@$site:$remotefile]&lt;BR /&gt;if { $result == 0 } {&lt;BR /&gt;        send_user "\nSCP program $scpprog failed to start!\n"&lt;BR /&gt;        exit 1&lt;BR /&gt;}&lt;BR /&gt;sleep 1&lt;BR /&gt;&lt;BR /&gt;set timeout $inittimeout&lt;BR /&gt;set isgood 0&lt;BR /&gt;&lt;BR /&gt;# nudge SCP along, answering "yes" and giving password&lt;BR /&gt;set needrepeat 1&lt;BR /&gt;while { $needrepeat != 0 } {&lt;BR /&gt;        set needrepeat 0&lt;BR /&gt;        expect {&lt;BR /&gt;                "assword" {&lt;BR /&gt;                        sleep 1&lt;BR /&gt;                        send "$password\r"&lt;BR /&gt;                        set isgood 1&lt;BR /&gt;                }&lt;BR /&gt;                "re you sure you want" {&lt;BR /&gt;                        sleep 1&lt;BR /&gt;                        send "yes\r"&lt;BR /&gt;                        set needrepeat 1&lt;BR /&gt;                }&lt;BR /&gt;                timeout {&lt;BR /&gt;                        send_user "\nSCP program $scpprog failed to connect!\n"&lt;BR /&gt;                        exit 1&lt;BR /&gt;                }&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;if { $isgood != 1 } {&lt;BR /&gt;        send_user "\nSCP failed to establish connection!\n";&lt;BR /&gt;        exit 1&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;set timeout $conntimeout&lt;BR /&gt;set isgood 0&lt;BR /&gt;&lt;BR /&gt;# wait for SCP to complete transferring the file&lt;BR /&gt;expect {&lt;BR /&gt;        "ermission denied" {&lt;BR /&gt;                send_user "\nSCP did not like that password!\n"&lt;BR /&gt;                exit 1&lt;BR /&gt;        }&lt;BR /&gt;        "100%" {&lt;BR /&gt;                set isgood 1&lt;BR /&gt;                send_user "\nDone!\n"&lt;BR /&gt;                exit 1&lt;BR /&gt;        }&lt;BR /&gt;        timeout {&lt;BR /&gt;                send_user "\nSCP failed to work after giving password!\n"&lt;BR /&gt;                exit 1&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;if { $isgood != 1 } {&lt;BR /&gt;        send_user "\nSCP failed during upload of the file!\n"&lt;BR /&gt;        exit 1&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;# see if it worked&lt;BR /&gt;set resultlist [wait -i $spawn_id]&lt;BR /&gt;set resultstatus [lindex $resultlist 2]&lt;BR /&gt;set resultcode [lindex $resultlist 3]&lt;BR /&gt;if { $resultstatus != 0 } {&lt;BR /&gt;        send_user "\nSystem error $resultcode while running SCP program!\n";&lt;BR /&gt;        exit 1&lt;BR /&gt;}&lt;BR /&gt;if { $resultcode != 0 } {&lt;BR /&gt;        send_user "\nError $resultcode returned by SCP program!\n";&lt;BR /&gt;        exit 1&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;exit 0</description>
      <pubDate>Fri, 24 Jul 2009 14:28:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189346#M461309</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-07-24T14:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: expect script for sftp file transfer.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189347#M461310</link>
      <description>Thanks for the solution.</description>
      <pubDate>Mon, 27 Jul 2009 04:42:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-for-sftp-file-transfer/m-p/5189347#M461310</guid>
      <dc:creator>Narendra Uttekar</dc:creator>
      <dc:date>2009-07-27T04:42:19Z</dc:date>
    </item>
  </channel>
</rss>

