2

私はexpファイルを実行しようとします:

#!/usr/bin/expect

# mysql credentials and connection data
current_db_name='webui_dev'
new_db_name='db_2013'
db_host='localhost'
db_user='root'
db_pass=''


# using a here-document to pass commands to expect. 
# (the commands could be stored in a file as well)
expect <<EOF
  log_user 0
  spawn mysqldump -h "$db_host" -u "$db_user" -p "$current_db_name" | mysql -h "$db_host" -u "$db_user" -p "$new_db_name"
  expect "password:"
  send "$db_pass\r"
  log_user 1
  expect eof
EOF

-fフラグを付けて if を実行すると、エラーが発生します。mysqldump: Couldn't find table: "|"

このアプローチを試してみると

exp_internal 1
  spawn sh -c  "mysqldump -h \"$db_host\" -u \"$db_user\" -p \"$current_db_name\" | mysql -h \"$db_host\" -u \"$db_user\" -p \"$new_db_name\" "

出力が得られます

expect: option requires an argument -- f
usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {81914}

expect: does "" (spawn_id exp7) match glob pattern "password:"? no

expect: does "Enter password: " (spawn_id exp7) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "Enter password:"
send: sending "\r" to { exp7 }

Enter password: expect: timed out
4

3 に答える 3

0

私のMacでは、次のコマンドを使用しました:

mysqldump -u root -p [database_name] > /Users/rgavila/Documents/_WSCenter/Backup-Jul-5-2021.sql

シェブロン (>) を含めて、必要な場所にファイルを押し出すのと同じくらい簡単でした。

動作中に画面が静かになりました。

于 2021-07-06T03:28:28.663 に答える