Register
It is currently Thu Sep 18, 2014 1:42 pm

setting a variable to execute a command string plus...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Jan 22, 2014 1:26 pm   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
I am doing this script that does quite a bit of things to user accounts, but I am curious if I could make this portion into a variable:

Say I have several users; tom, burt, ernie, etc and I want to make sure that their accounts are set to never expire, etc. Currently, I am doing:
Code:
chage -I -1 -m 0 -m -99999 -E -1 tom
<other code for the above user>

chage -I -1 -m 0 -m -99999 -E -1 burt
<other code for the above user>

chage -I -1 -m 0 -m -99999 -E -1 ernie
<other code for the above user>


Just looking for a way to put the initial command string into a variable, then call out the user name...such as
Code:
CHAGE=`chage -I -1 -m 0 -m -99999 -E -1`
<other code>
$CHAGE tom
<other code>
$CHAGE burt
<other code>
$CHAGE ernie
<other code>


as it sits above, I get usage errors, then help options for chage, then "command not found" errors for tom, etc.

I wasn't really interested in creating a list or polling from a list and having the command loop through anything, just a way to bind the CHAGE variable to whatever username I would give it.
thanks!


Top
 Profile  
 PostPosted: Thu Jan 23, 2014 5:20 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 546
hi,

the best/safest way to do such a thing would be to use a function:
Code:
yourOwnChage() {
   chage -I -1 -m 0 -m -99999 -E -1 "$1"
   <other code that may not change>
}


Top
 Profile  
 PostPosted: Thu Jan 23, 2014 9:40 am   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
Watael wrote:
hi,

the best/safest way to do such a thing would be to use a function:
Code:
yourOwnChage() {
   chage -I -1 -m 0 -m -99999 -E -1 "$1"
   <other code that may not change>
}


<face palming myself> I didn't even think of making it into a function. o_O

Thanks!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP