Apparently, I can find out whether a Samba user needs a password change or not with the following command:pdbedit -v -u userid | grep Password must changeI also see I can list all the Samba users with the command:pdbedit -L -vWhich outputs about 10MB of data formatted like this:---------------Unix username:        egbjt005$NT username:          egbjt005$...Password must change: Thu, 16 Aug 2012 07:33:58 NZST...---------------Unix username:        eghwj001$NT username:          eghwj001$...Password must change: Fri, 20 Jul 2012 14:42:46 NZST...The ... indicates several lines of data that's not of interest. The date will be in the past if the password is overdue to be changed.What I really want  is a list of userids starting with a particular 2 character prefix (let's use eg as an example) that need a password change. How can I do this?
How to list and filter Samba users that need a password change?
password;samba
I'm going on some examples of pdbedit output I found online.  Yours might differ; if you can provide some examples of what it prints, this code can be more tailored to what you need.First, you need to find the usernames that match your prefix.  It seems that pdbedit output is in username: foo format, so you could use awk to do that:pdbedit -L -v | awk '/username:/ {print $2}'Then we need to find names that start with your prefix, so let's use grep:pdbedit -L -v | awk '/username:/ {print $2}' | grep ^egTo see if a particular user's password needs to change, we can just see whether grep found that string, by checking its return code:if pdbedit -v -u $name | grep -q Password must change ; then    echo $namefiPutting it all together with a loop that checks each name:for name in $(pdbedit -L -v | awk '/username:/ {print $2}' | grep ^eg); do    if pdbedit -v -u $name | grep -q Password must change ; then        echo $name    fidoneUpdate after you posted sample outputThat format is clearly not designed by someone who's a fan of normal Unix command-line text processing tools!  While you can, of course, do anything in any language, I'd probably move to something like Python or Perl to parse this one.  I chose Perl here because Python's handling of dates and times is abysmal.#!/usr/bin/perluse Date::Parse;$now = time();while (<>) {    if (/Unix username:\s*(.*)/) {        $username = $1;    }    if (/Password must change:\s*(.*)/) {        $change = str2time($1);        if ($change <= $now) {            print $username\n;        }    }}This will print the Unix username of any user whose password is expired.  Use it like:pdbedit -L -v | perl parse.plEdit by Question authorThe final code I used was:#!/usr/bin/perluse Date::Parse;$now = time();while (<>) {    if (/Unix username:\s*(.*)/) {        $username = $1;    }    if (/Password must change:\s*(.*)/) {        $expiry = $1;        $change = str2time($expiry);        if ($expiry !~ /^never/ && $change <= $now && $username =~ /^eg[a-z]{3}\d+/) {            print $username expiry: $expiry\n;        }    }}Which produces output like this:egdfd001 expiry: Mon, 30 Jul 2012 08:12:02 NZSTegjpf001 expiry: Mon, 13 Aug 2012 07:50:03 NZST