Friday, October 31, 2014

Shell csript linux auto connect ssh to server and deployment

I want deploy code to server. I dont want connect ssh in command. I write shell script linux auto connect to server and cd go to directory project and execute git command or svn command if it done exit connect .

- Step 1:  Install package expect  if not install on my computer.
- Step 2 : create file deploy_project.sh and paste code .
#!/usr/bin/expect
set login "root" # user  login
set addr "192.168.1.44" # ip server 
set pw "123456" # password login ssh 

spawn ssh $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "#"
send "cd /var/www/html/project_example\r" # go to directory project
expect "#"
send "git pull\r" # command git pull source code
expect "#"
send "exit\r" # disconnect to server 
interact # close shell
- Step 3 Open terminal cd to directory  run command ./deploy_project.sh

Please have any questions. 

Good Luck !

No comments:

Post a Comment