Linux.com

Two examples : VNC and rsync

Posted by: Anonymous Coward on August 04, 2006 01:38 PM

It's nice to launch VNC with the necessary password included on the command line. It's also nice to automate rsync without creating keys beforehand.

Just be aware that of course it's not super-safe to let plaintext passwords in your<nobr> <wbr></nobr>.yourshell_history.<nobr> <wbr></nobr>;)



My 2 eurocents contributions (wich can surely be improved)<nobr> <wbr></nobr>:



autovncviewer

<tt>#!/bin/bash
# Syntax : autovncviewer host password vncoption1 vncoption2<nobr> <wbr></nobr>...
# Example : autovncviewer mypc "weakpwd" -bgr233

host="$1"
password="$2"
shift
shift
[ -z "$TMP" ] && TMP=/tmp

cat > $TMP/autovncviewer.expect.tmp.$$ << EOF
#!/usr/bin/expect -f
set host [lindex \$argv 0]
set password [lindex \$argv 1]
set timeout -1
spawn vncviewer \$host $*
expect "assword:"
send "\$password\r"
expect eof
EOF

chmod 700 $TMP/autovncviewer.expect.tmp.$$
$TMP/autovncvie<nobr>w<wbr></nobr> er.expect.tmp.$$ "$host" "$password"
rm $TMP/autovncviewer.expect.tmp.$$</tt>
autorsync
<tt>#!/bin/bash
# Syntax : autorsync password rsyncoption1 rsyncoption2<nobr> <wbr></nobr>...
# Example : autorsync passwd -Pavz joe@machine1:/home/joe/data<nobr> <wbr></nobr>.

password="$1"
shift
[ -z "$TMP" ] && TMP=/tmp

cat > $TMP/autorsync.expect.tmp.$$ << EOF
#!/usr/bin/expect -f
set password [lindex \$argv 0]
set timeout -1
spawn rsync $*
expect {
        "(yes/no)" {
                send "yes\r"
                expect "assword:"
                send "\$password\r"
        }

        "assword:" { send "\$password\r" }
}
expect eof
EOF

chmod 700 $TMP/autorsync.expect.tmp.$$
$TMP/autorsync.expe<nobr>c<wbr></nobr> t.tmp.$$ "$password"
echo $?
rm $TMP/autorsync.expect.tmp.$$</tt>

#

Return to Automate interactive transactions with Expect