enter bash commands no expect

1

Good evening guys, I have an activity to do that needed me to use Expect to remove the user interaction in an SMTP communication. So in the body of the email I need to add the current date and 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 wish he would receive this command here but I do not know how to 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 to use the spawn commands but it does not accept the email, I do not know how to give continuity of it, nor can the data be passed by parameter as I need this script to be scheduled and run alone.     

asked by anonymous 28.08.2016 / 05:31

1 answer

0

You can pass arguments in the script call.

Example copied from Stackoverflow.

Script:

set username [lindex $argv 0];
set password [lindex $argv 1];
send_user "$username $password"

Calling the script

$ ./test.exp user1 pass1
user1 pass1

Note: I do not know what to expect, and I have not tested the proposed solution.

    
28.08.2016 / 06:04