---
title: "linux expect"
author: "heipark"
date: "2015-07-17T17:08:44Z"
tags: []
categories: ["操作系统"]
slug: "linux-expect"
draft: false
lastmod: "2015-07-17T17:09:07Z"
id: 2228257
url: "https://heipark.iteye.com/blog/2228257"
---

# 1. 创建、编辑文件go.sh

 

```
#!/usr/bin/expect

spawn sudo su admin

expect  "*password*" { send "13456\r\n" }

interact 
```

 

# 2. 设置权限

 

chmod u+x go.sh

# 3. 运行

./go.sh

 

因为我们要使用expect执行，所以使用命令sh go.sh是不行的，会报“linux expect spawn: command not found”错误。