rsync_backup / smb.py

Thomas Waldmann 7e56be4 



























# -*- coding: ascii
"""
sending smb network messages

author: Thomas Waldmann
license: BSD
"""

from subprocess import check_call 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),
        shell=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.