Reputation: 1123
I want to pass all the remote server names as shell script arguments and then want my script to copy the given file/directory to all remote servers. Below is my code.
#!/bin/bash
/usr/bin/expect <<EOD
#connect via scp
usr=Joe
pwd=Password
file_location=/home/file1.txt
for a in $@
do
spawn scp -r $file_location "$usr@$a:$file_location"
expect -nocase "password: "
send "$pwd\r"
expect eof
EOD
Username and password is same for all the remote servers. So I am hard-coding them for time being but while running the script I see a problem with that..
>./scp1.sh server1 server2
invalid command name "usr=Joe"
while executing
"usr=Joe"
Any help is appreciated. Thanks!
Upvotes: 0
Views: 507
Reputation: 10663
To read command line arguments from expect:
$argc - number items of arguments passed to a script.
$argv - list of the arguments.
$argv0 - name of the script.
This was take from this site
If you want more help with expect
then google about tcl
because expect
is an extension to tcl
language
Upvotes: 1