1. Thomas Waldmann
  2. rsync_backup


rsync_backup / smb.py

# -*- coding: ascii
sending smb network messages

author: Thomas Waldmann
license: BSD

from exec_cmd import exec_shell as cmd

SENDMSG = """echo "%(msg)s" | smbclient -U%(user)s%%%(password)s -M %(hostname)s"""

def send_msg(msg, hostname, user=None, password=None, unattended=True):
    """use smbclient to send a msg to hostname
    Note: do NOT give any user input to any parameter, it is unsafe.
    if unattended:
        # it seems like a dummy is OK, but if one does not give user and
        # password on the commandline, it will ask for it interactively:
        if user is None:
            user = "server" # it will say "message from <user> ..." in the popup
        if password is None:
            password = user
    cmd(SENDMSG % dict(msg=msg, hostname=hostname, user=user, password=password))