Microsoft
Software
Hardware
Network
Question : Silmulate keystrokes in bash script
Hi experts,
I was wondering if someone could help me out with a bash script.
I have script that simply does an scp
scp *.js
[email protected]
:/
Is there a way to add the password info and enter key to the bash script so I don't have enter it everytime I run the script?
Thanks!
Answer : Silmulate keystrokes in bash script
Hi DanRaposo,
I was checking in my linux box and as "scp" does not provide an option to put the password, I can suggest you to use: "expect".
I created a very simple script that you can use, check below:
==========================
==========
==========
==========
==========
=========
#!/usr/bin/expect -f
set timeout -1
spawn scp test_file.txt root@localhost:/
match_max 100000
expect -exact "root@localhost's password: "
send -- "passxxword\r"
expect eof
==========================
==========
==========
==========
==========
=========
Above I put my script, and for yours would be something like:
==========================
==========
==========
==========
==========
=========
#!/usr/bin/expect -f
set timeout -1
spawn scp *.js
[email protected]
:/
match_max 100000
expect -exact "
[email protected]
's password: "
send -- "passxxword\r"
expect eof
==========================
==========
==========
==========
==========
=========
The scripts above are really simple and will not handle if you have a problem during the execution of "scp" like the "problem" below:
==========================
==========
==========
==========
==========
=========
The autenticity of host 'Hostname or Ip(ip address)' can't be established.
RSA Key fingerprint is xxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)?
==========================
==========
==========
==========
==========
=========
You can change the script to whatever you need and if you are not familiar with "expect", the "autoexpect" command can help you, just: "man autoexpect".
I hope it helps you. =0)
Random Solutions
Using NIS for Domain/Client
cgi cookie with multiple names / values
How to clone Windows 2000 system
Send link to File via Email
Fixing Audio-Video sync problems
BE duplicate backup set job losing 'recurring' status
Re IP an Exchange Server?
Pausing a load using Loader object?
Microsoft, Windows, 2003, Event 11167 DNSAPI
Ruby string manipulation, easy enough?