Pass variable to spawn
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in multiple servers.
#cat servers_list
server1
server2
server3
#cat user_create_script
spawn ssh -t user@$i sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
interact
Can anyone help me to achieve this.
shell scripting expect
New contributor
add a comment |Â
up vote
3
down vote
favorite
I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in multiple servers.
#cat servers_list
server1
server2
server3
#cat user_create_script
spawn ssh -t user@$i sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
interact
Can anyone help me to achieve this.
shell scripting expect
New contributor
would you please read this answer unix.stackexchange.com/questions/187339/spawn-command-not-found
â Goro
2 hours ago
1
@Goro, thanks alot. Given link is very helpful. My Problem solved. Thanks aton
â Dev
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in multiple servers.
#cat servers_list
server1
server2
server3
#cat user_create_script
spawn ssh -t user@$i sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
interact
Can anyone help me to achieve this.
shell scripting expect
New contributor
I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in multiple servers.
#cat servers_list
server1
server2
server3
#cat user_create_script
spawn ssh -t user@$i sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
interact
Can anyone help me to achieve this.
shell scripting expect
shell scripting expect
New contributor
New contributor
New contributor
asked 3 hours ago
Dev
211
211
New contributor
New contributor
would you please read this answer unix.stackexchange.com/questions/187339/spawn-command-not-found
â Goro
2 hours ago
1
@Goro, thanks alot. Given link is very helpful. My Problem solved. Thanks aton
â Dev
1 hour ago
add a comment |Â
would you please read this answer unix.stackexchange.com/questions/187339/spawn-command-not-found
â Goro
2 hours ago
1
@Goro, thanks alot. Given link is very helpful. My Problem solved. Thanks aton
â Dev
1 hour ago
would you please read this answer unix.stackexchange.com/questions/187339/spawn-command-not-found
â Goro
2 hours ago
would you please read this answer unix.stackexchange.com/questions/187339/spawn-command-not-found
â Goro
2 hours ago
1
1
@Goro, thanks alot. Given link is very helpful. My Problem solved. Thanks aton
â Dev
1 hour ago
@Goro, thanks alot. Given link is very helpful. My Problem solved. Thanks aton
â Dev
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
You'd have
user_create_script like this
#!/usr/bin/expect -f
set fh [open servers_list r]
while [gets $fh server_name] != -1
spawn ssh -t user@$server_name sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
expect eof
close $fh
I assume your remote user does not require a password for sudo.
More documentation about Tcl (upon which expect is built), including tutorials, is here: https://tcl.tk/doc/
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You'd have
user_create_script like this
#!/usr/bin/expect -f
set fh [open servers_list r]
while [gets $fh server_name] != -1
spawn ssh -t user@$server_name sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
expect eof
close $fh
I assume your remote user does not require a password for sudo.
More documentation about Tcl (upon which expect is built), including tutorials, is here: https://tcl.tk/doc/
add a comment |Â
up vote
3
down vote
You'd have
user_create_script like this
#!/usr/bin/expect -f
set fh [open servers_list r]
while [gets $fh server_name] != -1
spawn ssh -t user@$server_name sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
expect eof
close $fh
I assume your remote user does not require a password for sudo.
More documentation about Tcl (upon which expect is built), including tutorials, is here: https://tcl.tk/doc/
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You'd have
user_create_script like this
#!/usr/bin/expect -f
set fh [open servers_list r]
while [gets $fh server_name] != -1
spawn ssh -t user@$server_name sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
expect eof
close $fh
I assume your remote user does not require a password for sudo.
More documentation about Tcl (upon which expect is built), including tutorials, is here: https://tcl.tk/doc/
You'd have
user_create_script like this
#!/usr/bin/expect -f
set fh [open servers_list r]
while [gets $fh server_name] != -1
spawn ssh -t user@$server_name sudo /usr/sbin/useradd david
expect "password:"
send "pass123r"
expect eof
close $fh
I assume your remote user does not require a password for sudo.
More documentation about Tcl (upon which expect is built), including tutorials, is here: https://tcl.tk/doc/
answered 1 hour ago
glenn jackman
49k467105
49k467105
add a comment |Â
add a comment |Â
Dev is a new contributor. Be nice, and check out our Code of Conduct.
Dev is a new contributor. Be nice, and check out our Code of Conduct.
Dev is a new contributor. Be nice, and check out our Code of Conduct.
Dev is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475265%2fpass-variable-to-spawn%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
would you please read this answer unix.stackexchange.com/questions/187339/spawn-command-not-found
â Goro
2 hours ago
1
@Goro, thanks alot. Given link is very helpful. My Problem solved. Thanks aton
â Dev
1 hour ago