Results 1 to 2 of 2

Thread: Python/Terminal question

  1. #1
    Join Date
    Jul 2008
    Beans
    1

    Python/Terminal question

    Hello everyone and thanks in advance for any assistance provided. I'm attempting to list only usernames in terminal...then use that command in a python application. I've run into an issue, hopefully someone can provide assistance letting me know why it won't work or what I can do to get around it.

    Why does this work in terminal:
    Code:
    eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1
    But this does not work as python?:

    Code:
    #!/usr/bin/python3
    import sys, os
    def lisUser():
    print ("This is a current list of users on this system: ")
    os.system("eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1")
    lisUser()

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,521
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Python/Terminal question

    Your command works in bash but not in sh. os.system invokes sh. This works:
    Code:
    os.system("bash -c \"eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1\"")

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •