0

I am using a expect script & i am unable to set 2 variable to the output file, I just want to name the file as required.

#!/usr/bin/env expect
set file [lindex $argv 0];
set date [exec date "+%d-%B-%Y"]
spawn sh -c "ssh -o StrictHostKeyChecking=no hostname < ./script.sh > /root/scp_output_$file_$date.txt"

Required output

/root/scp_output_A_21-September-2017.txt
2

The error I see for some test code is

can't read "file_": no such variable
    while executing

which indicates that TCL is looking for a file_ variable that does not exist. This can be remedied by noting where the variable beings and end; TCL uses the same syntax as Perl for this, {} around the variable name.

spawn sh -c "ssh -o StrictHostKeyChecking=no hostname < ./script.sh > /root/scp_output_${file}_${date}.txt"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.