I have worked for a while on making a BASH
script to go through two lists and creating a command out of it.
In the end it should execute the command and synchronize my ZFS server and ZFS backup server.
Only pinnacle is that BASH
cant actually insert a password when a command ask's for it.
To my understanding this can be achieved with expect
.
The command is stored in $ExecuteSyncoid
And would look like this
/usr/sbin/syncoid <UserName>@<IP>:Storage/WallaBag Storage/Docker/WallaBag --compress none --sshcipher [email protected] --sshport <PortNumber> --sshkey </dest/to/keyfile> --no-privilege-elevation
The password is stored in $PWD
now i have to execute the expect
from within BASH since im not really in the mood to try and recreate all the code in expect/tcl
which i have never tried before.
The expect
part is
Enter passphrase for key '<nameOfKey>'
Now i dont understand tcl/expect
But I have made the attempts so far and i just cant make it work even one time
expect -c 'expect "Enter" { spawn $ExecuteCommand; send -- "$PWD\r"; interact }'
expect -c 'spawn $ExecuteSyncoid; expect "Enter"; send -- "$PWD\r"; interact'
syncoid command/password
/usr/bin/expect - <<EOF
spawn $ExecuteSyncoid
expect "Enter"
send -- "$PWD\r"
EOF
/usr/bin/expect <<EOD
spawn $ExecuteSyncoid
expect "Enter passphrase for key"
send -- "$PWD\r"
interact
EOD
/usr/bin/expect -c 'expect "Enter" { spawn $ExecuteSyncoid; send -- "$PWD\r" }'
I Allso attempted to make a seperate script
expect -f ./SynCoid-IterateThroughDataSets.exp $ExecuteSyncoid $PWD
With the code
#!/usr/bin/expect -f
set ExecuteSyncoid [lindex $argv 0];
set PWD [lindex $argv 1];
spawn $ExecuteSyncoid
expect "Enter"
send "\$PWD\r"
But unfortunately i cant figure out how to make expect see the $ExecuteSyncoid
command as one consistent command.
It wont execute it if i put it in quotos "" and if i dont have it in quotes the $ExecuteSyncoid
bash variable is considered multiple arguments in expect.
If anyone knows how to fix this, Or have an idea about what to do i would appreciate it.
Would allso be great if i could sse the output of the expect
command as it executes $ExecuteSyncoid
Best Regards, Darkyere