LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   passing a list of arguments to a command (http://www.linuxquestions.org/questions/linux-general-1/passing-a-list-of-arguments-to-a-command-321639/)

hdagelic 05-09-2005 08:56 AM

passing a list of arguments to a command
 
Hello,


I would like to use a "chage" command to set the password expiry date for all users. The problem is that the function takes only the single username as the argument:

chage -E date user

So, I'd like to combine it with "ls -1 /home" which gives me the list of usernames one in each row.

Is that possble somehow?

Thank you.

trevelluk 05-09-2005 09:08 AM

You could do this with a shell script:

Code:

#!/bin/bash

for user in `ls /home`; do
    chage -E date $user
done

But note that this will only work correctly if everything in /home is a directory corresponding to a username, and every user has their home directory under /home.

You can use cat /etc/passwd | cut -d':' -f1 to get a more reliable list of all the users, but this appoach will pick up all the system user accounts.

acid_kewpie 05-09-2005 09:30 AM

/etc/passwd is a much nicer route, and to avoid system accounts, i'd recommend filtering the uid or gid. depending on how your users are organised, if you have a fixed user group:
Code:

for i in $(cat /etc/passwd | cut -f 1,4 -d\:)
do
  if [ $(echo $i | cut -f 2 -d\:) -eq 100 ] then
    chage stuff...
  fi
done

games:100
user:100
chris:100
sarah:100



All times are GMT -5. The time now is 02:08 PM.