Coding locally and testing on a remote server, is often troublesome.
For example, forgetting to update the server results in useless tests.
Easiest way is to automatically synchronize the wanted folders.

For Windows I use WinSCP, which allows to easily to keep a remote directory updated.
For Linux, there is a script from Lukas Meyer:

  • livesync
    #infinite loop, we can end the script hitting ctrl+c
    #define options as array
    declare -a options#set first empty position with new value
    options[${#options[*]}]=”site3″;while [ true ] ; do
    #we create a menu to select which site to update
    select site in “${options[@]}” ; do
    #based on the selection, the syncscript with the proper arguments is called
    case ${site} in ${options[0]})
    syncscript /site1/local/folder server_ip1 username1 password1 /var/www ;
    syncscript site2/local/folder server_ip2 username2 password2 site2/remote/folder ;
    syncscript site3/local/folder server_ip3 username3 password3 site3/remote/folder ;
  • syncscript
    #!/usr/bin/expect -f
    #the she bangs line, to find out the path to expect on your system, type "which expect" on the shell
    #we get the command line arguments
    set localfolder [lrange $argv 0 0]
    set server_ip [lrange $argv 1 1]
    set username [lrange $argv 2 2]
    set password [lrange $argv 3 3]
    set remotefolder [lrange $argv 4 4]#this disables the timeout, so our script waits as long as it takes for the transfer
    set timeout -1
    #this calls rsync based on the command line args
    spawn rsync -r -a -v $localfolder $username@$server_ip:$remotefolder –exclude .svn
    #this avoids that if the output is to large, the earlier bytes won’t be fotgotten
    match_max 100000#we’re expecting the password prompt, we use a pattern so it can be anything that contains password: or Password
    expect “*?assword:*”
    #after we get the prompt we send the password
    send — “$password\r”
    #then we send a newline to make sure we get back to the command line
    send — “\r”#wait for the end-of-file in the output
    expect eof

Comments are closed.