溫馨提示×

Ubuntu expect腳本如何讀取外部文件

小樊
123
2024-07-17 14:32:52
欄目: 智能運維

要在Ubuntu上使用expect腳本讀取外部文件,可以使用以下步驟:

  1. 創建一個包含所需輸入的外部文件,例如input.txt。

  2. 編寫一個expect腳本,使用spawn命令啟動需要輸入的程序,并使用expect命令讀取外部文件中的輸入。

例如,假設我們有一個需要輸入用戶名和密碼的程序,并且我們想使用input.txt文件中的用戶名和密碼。以下是一個示例expect腳本:

#!/usr/bin/expect

set input_file "input.txt"
set file [open $input_file r]
gets $file username
gets $file password
close $file

spawn ./your_program

expect "Enter username:"
send "$username\r"

expect "Enter password:"
send "$password\r"

interact
  1. 保存并運行上述expect腳本,確保將your_program替換為您要運行的實際程序。

這樣,expect腳本將讀取外部文件中的用戶名和密碼,并將其發送到需要輸入的程序中。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女