{"action":"created","issue":{"url":"https://api.github.com/repos/fabric/fabric/issues/1873","repository_url":"https://api.github.com/repos/fabric/fabric","labels_url":"https://api.github.com/repos/fabric/fabric/issues/1873/labels{/name}","comments_url":"https://api.github.com/repos/fabric/fabric/issues/1873/comments","events_url":"https://api.github.com/repos/fabric/fabric/issues/1873/events","html_url":"https://github.com/fabric/fabric/issues/1873","id":359692841,"node_id":"MDU6SXNzdWUzNTk2OTI4NDE=","number":1873,"title":"fabric2, error in sudo command with pipe and string \"INFO\"","user":{"login":"youattd","id":1993643,"node_id":"MDQ6VXNlcjE5OTM2NDM=","avatar_url":"https://avatars1.githubusercontent.com/u/1993643?v=4","gravatar_id":"","url":"https://api.github.com/users/youattd","html_url":"https://github.com/youattd","followers_url":"https://api.github.com/users/youattd/followers","following_url":"https://api.github.com/users/youattd/following{/other_user}","gists_url":"https://api.github.com/users/youattd/gists{/gist_id}","starred_url":"https://api.github.com/users/youattd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youattd/subscriptions","organizations_url":"https://api.github.com/users/youattd/orgs","repos_url":"https://api.github.com/users/youattd/repos","events_url":"https://api.github.com/users/youattd/events{/privacy}","received_events_url":"https://api.github.com/users/youattd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-12T23:51:56Z","updated_at":"2018-09-13T15:45:19Z","closed_at":null,"author_association":"NONE","body":"### \r\n\r\nWhen called from Connection.sudo like this:\r\n\r\n```\r\nrslt = myconnection.sudo(mycmd, pty=True, hide='both')\r\n```\r\n\r\nthese commands all fail.  The presence of the string `INFO` in the pipe destination (literal or not) seems to cause the failure.\r\n\r\n```\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -E -i -v -e ERROR: -e info:'\"  # fails (note -i)\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -E -v -e INFO:'\"  # fails\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -v INFO:'\"  # fails\r\nmycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -v INFO'\"  # fails\r\n```\r\n\r\nWith this error and traceback:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"./fab-info-bug.py\", line 29, in <module>\r\n    rslt = c.sudo(mycmd, pty=True, hide='both')\r\n  File \"<decorator-gen-4>\", line 2, in sudo\r\n  File \"/usr/local/lib/python2.7/site-packages/fabric/connection.py\", line 30, in opens\r\n    return method(self, *args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/fabric/connection.py\", line 642, in sudo\r\n    return self._sudo(self._remote_runner(), command, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/invoke/context.py\", line 212, in _sudo\r\n    return runner.run(cmd_str, watchers=watchers, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/invoke/runners.py\", line 271, in run\r\n    return self._run_body(command, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/invoke/runners.py\", line 404, in _run_body\r\n    raise UnexpectedExit(result)\r\ninvoke.exceptions.UnexpectedExit: Encountered a bad command exit code!\r\n\r\nCommand: \"sudo -S -p '[sudo] password: ' -H -u postgres bash -c '/bin/grep 2018-09-04 your-remote-log-file | /bin/grep -v INFO'\"\r\n\r\nExit code: 1\r\n\r\nStdout:\r\n\r\n[sudo] password: \r\n\r\nStderr: n/a (PTYs have no stderr)\r\n```\r\n\r\nThese (below) succeed.\r\n\r\n```\r\n#mycmd = \"bash -c '/bin/grep -c INFO: \" + LOG_FILE + \"'\"  # works\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -E -v -e ERROR: -e info:'\"  # works\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -v WARN:'\"  # works\r\n```\r\nTest program (using python 2.7 on Mac OS.  remote host is Amazon LInux):\r\n\r\n```\r\n#!/usr/bin/env python\r\n\r\nfrom __future__ import print_function\r\nimport os\r\nfrom fabric import Connection, Config\r\n\r\n\r\nSUDO_PASS = 'yoursudopwd'\r\nSUDO_USER = 'yoursudouser'\r\nLOG_FILE = \"log-file-on-remote-server\"\r\n\r\nconfig = Config(overrides={'sudo': {'password': SUDO_PASS, 'user': SUDO_USER}})\r\n\r\nc = Connection('yourhostname', user=\"yoursshuser\", config=config)\r\nc.connect_kwargs[\"key_filename\"] = os.path.expandvars(\"$HOME/.ssh/Support\")\r\nc.connect_kwargs[\"passphrase\"] = \"yoursshpassphrase\"\r\nc.load_ssh_configs = False\r\n\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -E -i -v -e ERROR: -e info:'\"  # fails (note -i)\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -E -v -e INFO:'\"  # fails\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -v INFO:'\"  # fails\r\nmycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -v INFO'\"  # fails\r\n\r\n#mycmd = \"bash -c '/bin/grep -c INFO: \" + LOG_FILE + \"'\"  # works, no pipe\r\n\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -E -v -e ERROR: -e info:'\"  # works, lowercase \"info\" is ok.\r\n#mycmd = \"bash -c '/bin/grep 2018-09-04 \" + LOG_FILE + \" | /bin/grep -v WARN:'\"  # works\r\n\r\nrslt = c.sudo(mycmd, pty=True, hide='both')\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/fabric/fabric/issues/comments/421054414","html_url":"https://github.com/fabric/fabric/issues/1873#issuecomment-421054414","issue_url":"https://api.github.com/repos/fabric/fabric/issues/1873","id":421054414,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTA1NDQxNA==","user":{"login":"youattd","id":1993643,"node_id":"MDQ6VXNlcjE5OTM2NDM=","avatar_url":"https://avatars1.githubusercontent.com/u/1993643?v=4","gravatar_id":"","url":"https://api.github.com/users/youattd","html_url":"https://github.com/youattd","followers_url":"https://api.github.com/users/youattd/followers","following_url":"https://api.github.com/users/youattd/following{/other_user}","gists_url":"https://api.github.com/users/youattd/gists{/gist_id}","starred_url":"https://api.github.com/users/youattd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youattd/subscriptions","organizations_url":"https://api.github.com/users/youattd/orgs","repos_url":"https://api.github.com/users/youattd/repos","events_url":"https://api.github.com/users/youattd/events{/privacy}","received_events_url":"https://api.github.com/users/youattd/received_events","type":"User","site_admin":false},"created_at":"2018-09-13T15:45:19Z","updated_at":"2018-09-13T15:45:19Z","author_association":"NONE","body":"Thanks Pierce.\nI'm aware that \"-v\" inverts the search and does not mean verbose.\nWill RTFM for handling non-zero bash return codes.\n\n\n\nOn Thu, Sep 13, 2018 at 1:03 AM Pierce Lopez <notifications@github.com>\nwrote:\n\n> The environment variables LANG and LC_ALL can affect how grep does\n> case-insensitive matches. That's the only thing possibly fabric related\n> that I can think of which might be affecting your grep commands.\n>\n> Note that grep -v means \"inverse\" (not \"verbose\"). So if *all* lines\n> include \"INFO:\", then grep -v INFO will match *zero* lines and will exit\n> with an error code, while grep -v -e ERROR: -e info: will match all lines\n> (because the expressions do not match, then -v inverts aka reverses that).\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/fabric/fabric/issues/1873#issuecomment-420919532>, or mute\n> the thread\n> <https://github.com/notifications/unsubscribe-auth/AB5rq8j4wRCwLpfnKCocHlPK2BSlFoFaks5uahFAgaJpZM4WmWKW>\n> .\n>\n"}}
{"actor":{"display_login":"youattd"}}