I am trying to spawn scp command to copy one file from one server to another server. So, I am passing 8 arguments to an expect script as follows

expect my_x_script.exp file_src file_dest s_user s_pass s_host d_user d_pass d_host

Is it valid to pass these many arguments to an expect script?

  • it does successful copy from one remote machine to another remote machine – firoj_mujawar Oct 13 '16 at 11:13

Yes there's no problem with that many arguments. Depending on your expect version, you extract the values with one of these:

lassign $::argv \
    src_file  src_user  src_pass  src_host \
    dest_file dest_user dest_pass dest_host
# or
foreach {src_file src_user src_pass src_host dest_file dest_user dest_pass dest_host} $::argv {break}

At some point, the user interface gets hard to manage though. You might want to look into using command line options to help keep things straight. Check out the cmdline package from tcllib. Then you can do:

expect my_x_script.exp \
    -src_file file_src \
    -src_user s_user \
    -src_pass s_pass \
    -src_host s_host \
    -dest_file file_dest \
    -dest_user d_user \
    -dest_pass d_pass \
    -dest_host d_host

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.