<?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 Expect script to notify if server is down in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-to-notify-if-server-is-down/m-p/4569798#M679131</link>
    <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I have the following expect script that runs automatically when called by a shell script. I am trying to figure out a way to notify me or log somewhere if the server is down or if the process cannot connect to the server for any reason.&lt;BR /&gt;&lt;BR /&gt;Expect script is below:&lt;BR /&gt;#!/opt/expect/expect&lt;BR /&gt;# procedure to attempt connecting; result 0 if OK, 1 elsewhere&lt;BR /&gt; proc connect {password} {&lt;BR /&gt;  expect {&lt;BR /&gt;    "Password:" {&lt;BR /&gt;        send "$password\r"&lt;BR /&gt;        expect {&lt;BR /&gt;           "sftp*" {&lt;BR /&gt;                return 0&lt;BR /&gt;            }&lt;BR /&gt;        }&lt;BR /&gt;     }&lt;BR /&gt;  }&lt;BR /&gt;  # timed out&lt;BR /&gt;  return 1&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt;# first step is to assign the arguments to appropriate variables&lt;BR /&gt;set argc [llength $argv]&lt;BR /&gt;set user_id [lindex $argv 0]&lt;BR /&gt;set password [lindex $argv 1]&lt;BR /&gt;set host_id [lindex $argv 2]&lt;BR /&gt;set upload_dir [lindex $argv 3]&lt;BR /&gt;set directory [lindex $argv 4]&lt;BR /&gt;set filename [lindex $argv 5]&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;spawn /usr/local/bin/sftp2 $user_id@$host_id&lt;BR /&gt;set rez [connect $password]&lt;BR /&gt;if { $rez == 0 } {&lt;BR /&gt;send "cd $upload_dir\r"&lt;BR /&gt;expect "sftp&amp;gt;"&lt;BR /&gt;send "lcd $directory\r"&lt;BR /&gt;expect "sftp&amp;gt;"&lt;BR /&gt;set timeout -1&lt;BR /&gt;send "put $filename\r"&lt;BR /&gt;expect "sftp&amp;gt;"&lt;BR /&gt;send "quit\r"&lt;BR /&gt;expect eof&lt;BR /&gt;exit 0&lt;BR /&gt;}&lt;BR /&gt;puts "\nError connecting to the server:\n"&lt;BR /&gt;exit 1&lt;BR /&gt;&lt;BR /&gt;I need the "Error connecting to the server" message emailed to me anytime it happens. Is there a way possible to do this using expect.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.</description>
    <pubDate>Fri, 22 Jan 2010 21:16:52 GMT</pubDate>
    <dc:creator>Robert Legatie</dc:creator>
    <dc:date>2010-01-22T21:16:52Z</dc:date>
    <item>
      <title>Expect script to notify if server is down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-to-notify-if-server-is-down/m-p/4569798#M679131</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I have the following expect script that runs automatically when called by a shell script. I am trying to figure out a way to notify me or log somewhere if the server is down or if the process cannot connect to the server for any reason.&lt;BR /&gt;&lt;BR /&gt;Expect script is below:&lt;BR /&gt;#!/opt/expect/expect&lt;BR /&gt;# procedure to attempt connecting; result 0 if OK, 1 elsewhere&lt;BR /&gt; proc connect {password} {&lt;BR /&gt;  expect {&lt;BR /&gt;    "Password:" {&lt;BR /&gt;        send "$password\r"&lt;BR /&gt;        expect {&lt;BR /&gt;           "sftp*" {&lt;BR /&gt;                return 0&lt;BR /&gt;            }&lt;BR /&gt;        }&lt;BR /&gt;     }&lt;BR /&gt;  }&lt;BR /&gt;  # timed out&lt;BR /&gt;  return 1&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt;# first step is to assign the arguments to appropriate variables&lt;BR /&gt;set argc [llength $argv]&lt;BR /&gt;set user_id [lindex $argv 0]&lt;BR /&gt;set password [lindex $argv 1]&lt;BR /&gt;set host_id [lindex $argv 2]&lt;BR /&gt;set upload_dir [lindex $argv 3]&lt;BR /&gt;set directory [lindex $argv 4]&lt;BR /&gt;set filename [lindex $argv 5]&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;spawn /usr/local/bin/sftp2 $user_id@$host_id&lt;BR /&gt;set rez [connect $password]&lt;BR /&gt;if { $rez == 0 } {&lt;BR /&gt;send "cd $upload_dir\r"&lt;BR /&gt;expect "sftp&amp;gt;"&lt;BR /&gt;send "lcd $directory\r"&lt;BR /&gt;expect "sftp&amp;gt;"&lt;BR /&gt;set timeout -1&lt;BR /&gt;send "put $filename\r"&lt;BR /&gt;expect "sftp&amp;gt;"&lt;BR /&gt;send "quit\r"&lt;BR /&gt;expect eof&lt;BR /&gt;exit 0&lt;BR /&gt;}&lt;BR /&gt;puts "\nError connecting to the server:\n"&lt;BR /&gt;exit 1&lt;BR /&gt;&lt;BR /&gt;I need the "Error connecting to the server" message emailed to me anytime it happens. Is there a way possible to do this using expect.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.</description>
      <pubDate>Fri, 22 Jan 2010 21:16:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-to-notify-if-server-is-down/m-p/4569798#M679131</guid>
      <dc:creator>Robert Legatie</dc:creator>
      <dc:date>2010-01-22T21:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Expect script to notify if server is down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-to-notify-if-server-is-down/m-p/4569799#M679132</link>
      <description>I did find it, I can use the command&lt;BR /&gt;exec echo "string" | mailx -s "Subject" &lt;USER&gt;&lt;/USER&gt;</description>
      <pubDate>Fri, 22 Jan 2010 22:29:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expect-script-to-notify-if-server-is-down/m-p/4569799#M679132</guid>
      <dc:creator>Robert Legatie</dc:creator>
      <dc:date>2010-01-22T22:29:44Z</dc:date>
    </item>
  </channel>
</rss>

