linux - Script to perform remote login and execute another local script -
i have write script performs remote login , authentication , execute local script on remote.
my original code this:
#!/usr/bin/expect spawn ssh user@ip "bash -ls" < ./script.bash expect "password" send "abc123/r" interact
which gives following on running ./my_script.sh
spawn ssh user@ip "bash -ls" < ./script.bash user@ip's password: ./script.bash: no such file or directory
however, if run script without argument i.e. just
#!/usr/bin/expect spawn ssh user@ip expect "password" send "abc123/r" interact
it gets login.
also if run directly through terminal without script like
ssh user@ip "bash -ls" < ./script.bash
then local file getting executed @ remote server after taking password through prompt. hence can please suggest how make original code work successfully.
that's because expect not understand shell's input redirection. try this:
spawn sh -c {ssh user@ip "bash -ls" < ./script.bash}
if "user" or "ip" variable, we'll need different quoting. such
spawn sh -c "ssh $user@$ip 'bash -ls' < ./script.bash"
Comments
Post a Comment