Monday, 30 January 2012

Access the server through ssh login using bash script


1. Install expect using yum
$ yum install expect

2. create a blank file and copy the below line
$ vi script.sh

#!/bin/expect
#!/bin/bash
password='password'
expect -c "
spawn ssh username@IP -p portnumber
expect password
send $password\r
interact
"
3. execute the script
$ sh script.sh

No comments:

Post a Comment