LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-09-2005, 08:56 AM   #1
hdagelic
LQ Newbie
 
Registered: Sep 2003
Location: Zagreb, Croatia
Distribution: rh9, debian
Posts: 28

Rep: Reputation: 15
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.
 
Old 05-09-2005, 09:08 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
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.
 
Old 05-09-2005, 09:30 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
/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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing arguments to a shell script subu_s Programming 3 09-02-2005 05:13 AM
Problem with passing arguments in Perl bahadur Programming 1 05-30-2005 01:47 AM
Passing Arguments into the Thread Function George_gk Programming 2 01-31-2005 05:03 AM
Handline passing arguments in C AMMullan Programming 9 03-22-2004 01:37 AM
Issue with recursive script passing arguments gauge73 Linux - Newbie 0 01-06-2004 07:16 PM


All times are GMT -5. The time now is 09:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration