insert bash commands into expect

Asked

Viewed 504 times

2

Good evening guys, I have an activity to do that I needed to use Expect to remove user interaction in an SMTP communication. Only that in the body of the email I need to add the current date and the size of a file. the code is like this

#!/usr/bin/expect
puts "Enviando e-mail para Administrador!!"
spawn telnet 192.168.0.102 25
expect "%"
send "helo script.com.br\r"
expect "%"
send "mail from: [email protected]\r"
expect "%"
send"rcpt to: [email protected]\r"
expect "%"
send "data\r"
expect "%"
send "Backup concluido com sucesso\r"
send ".\r"
expect "%"
send "quit\r"
expect eof

but I’d like him to get that command here but I don’t know how I do it

#!/usr/bin/expect
DATA=$(date)
TAMARQ=$(ls -l | grep "arquivo_bakcup" | awk '{print $5}')
puts "Enviando e-mail para Administrador!!"
spawn telnet 192.168.0.102 25
expect "%"
send "helo script.com.br\r"
expect "%"
send "mail from: [email protected]\r"
expect "%"
send"rcpt to: [email protected]\r"
expect "%"
send "data\r"
expect "%"
send "Backup concluido com sucesso\r"
send "$DATA Tamanho do arquivo de backup: $TAMARQ\r"
send ".\r"
expect "%"
send "quit\r"
expect eof

I tried using the Spawn command but it does not accept in the email, I do not know how to continue there, and also can not the data be passed by parameter because I need this script to be scheduled and run alone.

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.