Search code examples
linuxvariablessamba

How to use a variable in a single command - Bash


ISSUE/QUESTION:

How can I run this single command against each user; using $USER as the variable, listed in a text file, for example.

WHY:

I am developing a script that will check a user's password expiration date in Samba 3.x.

THOUGHTS:

I believe some form of the "FOR" function could work but I am having troubles making it effective and I am pressed for time.

pdbedit -Lv $USER

(Note: This is not the complete command, just to simplify my problem area.)

I appreciate the help. I understand this is (should be) simple. Today I woke up on the wrong foot or something because I can't seem to connect the dots on much anything today...

Cheers


Solution

  • while read yourUser
    do
      pdbedit -Lv $yourUser
    done < users.txt
    

    If users.txt has a blank line at the end that is fine, other wise you'll need another echo.

    if [ $yourUser ]
    then
      pdbedit -Lv $yourUser
    fi