{"id":18804366,"url":"https://github.com/abates/ruby_expect","last_synced_at":"2025-07-10T07:34:38.154Z","repository":{"id":6115079,"uuid":"7342947","full_name":"abates/ruby_expect","owner":"abates","description":"Ruby implementation for send/expect interaction","archived":false,"fork":false,"pushed_at":"2020-07-09T17:33:35.000Z","size":69,"stargazers_count":72,"open_issues_count":0,"forks_count":11,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2025-06-15T07:42:16.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-27T16:38:47.000Z","updated_at":"2024-12-17T07:54:41.000Z","dependencies_parsed_at":"2022-07-28T19:39:45.844Z","dependency_job_id":null,"html_url":"https://github.com/abates/ruby_expect","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/abates/ruby_expect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abates%2Fruby_expect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abates%2Fruby_expect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abates%2Fruby_expect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abates%2Fruby_expect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abates","download_url":"https://codeload.github.com/abates/ruby_expect/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abates%2Fruby_expect/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264545173,"owners_count":23625405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T22:39:05.076Z","updated_at":"2025-07-10T07:34:38.094Z","avatar_url":"https://github.com/abates.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"RubyExpect\n==========\n[![Gem Version](https://badge.fury.io/rb/ruby_expect.svg)](https://badge.fury.io/rb/ruby_expect)\n[![Build Status](https://travis-ci.org/abates/ruby_expect.svg?branch=develop)](https://travis-ci.org/abates/ruby_expect)\n\nIntroduction\n------------\n\nThis is a simple expect API written in pure ruby. Part of this library includes a simple procedure DSL\nfor creating sequences of expect/send behavior. \n\nExamples\n--------\n\n### SSH to a host and run a command\nThis example will use the system ssh binary and connect to a host.  Upon connecting it will\nexecute a command and wait for the response then exit.  The response from the command will be\nparsed and printed to the screen.\n\n```ruby\n#!/usr/bin/ruby\n\nrequire 'ruby_expect'\n\nusername = 'username'\npassword = 'password'\nhostname = 'hostname'\n\nexp = RubyExpect::Expect.spawn(\"/usr/bin/ssh #{username}@#{hostname}\")\n\nexp.procedure do\n  retval = 0\n  while (retval != 2)\n    retval = any do\n      expect /Are you sure you want to continue connecting \\(yes\\/no\\)\\?/ do\n        send 'yes'\n      end\n\n      expect /password:\\s*$/ do\n        send password\n      end\n\n      expect /\\$\\s*$/ do\n        send 'uptime'\n      end\n    end\n  end\n\n  # Expect each of the following\n  each do\n    expect /load\\s+average:\\s+\\d+\\.\\d+,\\s+\\d+\\.\\d+,\\s+\\d+\\.\\d+/ do # expect the output of uptime\n      puts last_match.to_s\n    end\n\n    expect /\\$\\s+$/ do # shell prompt\n      send 'exit'\n    end\n  end\nend\n```\n\n### Interact with a local script\nThis example runs a script and interacts with it\n```ruby\n#!/usr/bin/ruby\n\nrequire 'ruby_expect'\n\nroot_password = 'root_password'\nnew_root_password = 'new_password'\n\nexp = RubyExpect::Expect.spawn('mysql_secure_installation', :debug =\u003e true)\n\nexp.procedure do\n  each do\n    expect \"Enter current password for root (enter for none):\" do\n      send root_password\n    end\n\n    expect \"Change the root password? [Y/n]\" do\n      send \"y\"\n    end\n\n    expect \"New password:\" do\n      send new_root_password\n    end\n\n    expect \"Re-enter new password:\" do\n      send new_root_password\n    end\n\n    expect \"Remove anonymous users?\" do\n      send \"y\"\n    end\n\n    expect \"Disallow root login remotely?\" do\n      send \"y\"\n    end\n\n    expect \"Remove test database and access to it?\" do\n      send \"y\"\n    end\n\n    expect \"Reload privilege tables now?\" do\n      send \"y\"\n    end\n  end\nend\n\nputs \"Ended expect script.\"\n```\n\n\n### SSH to a host and interact\nThis example will spawn ssh and login to the host.  Once logged in, the interact\nmethod is called which returns control to the user and allows them to interact\ndirectly with the remote system\n\n```ruby\n#!/usr/bin/ruby\n\nrequire 'ruby_expect'\n\nusername = 'username'\npassword = 'password'\nhostname = 'hostname'\n\nexp = RubyExpect::Expect.spawn(\"/usr/bin/ssh #{username}@#{hostname}\")\nexp.procedure do\n  retval = 0\n  while (retval != 2)\n    retval = any do\n      # Accept the key if it isn't already known\n      expect /Are you sure you want to continue connecting \\(yes\\/no\\)\\?/ do\n        send 'yes'\n      end\n\n      # Send the password at the prompt\n      expect /password:\\s*$/ do\n        send password\n      end\n\n      # Expect the shell prompt\n      expect /\\$\\s*$/ do\n        send \"\"\n      end\n    end\n  end\nend\n\n# Pass control back to the user\nexp.interact\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabates%2Fruby_expect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabates%2Fruby_expect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabates%2Fruby_expect/lists"}