Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: Script to create group specific symbolic links for new users

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Script to create group specific symbolic links for new users

    I'm currently working on a script that will automate symbolic links for new users that access our redhat 5 systems. I want this script to gather information about what groups they are in and then add the corresponding links to their home directory so I don't have to do it.

    Currently I have this:
    Code:
    !/bin/bash
    
    for name  in `groups`; do
    ln -s /u03/dl/$name /home/`whoami`;
    done
    This works except I've forgotten I don't need it to make a script for groups that don't have links like the group that is their user name or wheel etc. Can I specify which groups and still use the groups command? Or will I need to add a fancy if statement in there.

    Thanks,

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    445
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    9

    Default

    hi,

    bash can handle this using extglobs
    Code:
    #!/bin/bash
    
    shopt -s extglob nullglob
    
    userGroups=$(groups)
    user=$(whoami)
    for group in ${userGroups//@($user|wheel)}
    do ln -s /u03/dl/$group /home/$user
    done
    A problem clearly stated is a problem half solved.

  3. The Following User Says Thank You to Watael For This Useful Post:

    vaibhav.kanchan (11th December 2012)

  4. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by Watael View Post
    hi,

    bash can handle this using extglobs
    Code:
    #!/bin/bash
    
    shopt -s extglob nullglob
    
    userGroups=$(groups)
    user=$(whoami)
    for group in ${userGroups//@($user|wheel)}
    do ln -s /u03/dl/$group /home/$user
    done
    For multiple groups can i just do ($user|wheel)($user|group2)?

  5. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    445
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    9

    Default

    just add group2
    Code:
    @($user|wheel|group2)
    A problem clearly stated is a problem half solved.

  6. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by Watael View Post
    just add group2
    Code:
    @($user|wheel|group2)

    This appears to do sort of the opposite of what I needed. Instead of making 2 links for each group it make a link for every group but the two specified.

  7. #6
    Senior Member
    Join Date
    Aug 2011
    Posts
    445
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    9

    Default

    I probably misunderstood what your needs

    what have you got ?
    what do you want to have?
    A problem clearly stated is a problem half solved.

  8. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Sure,

    I have new users who will be logging in at some point and instead of creating these symbolic links to /u03/dl/group1 /home/user and /u03/dl/group2 /home/user I'd rather have this script that takes 2 specified groups I know have directories relative to them
    so say group1 has directory /u03/dl/group1 so if user is in group1 they need symbolic link for that directory in their home directory to make their lives easier. I just wanted to make this process easier as opposed to them having to call me every time a new user is added to the system.

  9. #8
    Senior Member
    Join Date
    Aug 2011
    Posts
    445
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    9

    Default

    it's not very clear yet.

    say user1 is part of group1 and group2
    (s)he uses the script, so /U03/dl/group1 and /U03/dl/group2 are linked to his/er home
    `groups` shows user1's groups (s)he is in (group1 and in group2)
    then
    Code:
    for group in $(groups); do ln -s /U03/dl/$group $HOME/; done
    does the job
    what exactly do you want?
    A problem clearly stated is a problem half solved.

  10. #9
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Well the thing is user1 will actually be in around 20 or 30 groups, but not all of them need to have links to directories only a specific 1 or 2 groups related to the user. And these will be the same 1 or 2 groups for every user as well.

    so say user1 has group1 through group20 but all i need links for is group2 and group13
    but not any of the other groups.

    Does that help?

  11. #10
    Senior Member
    Join Date
    Aug 2011
    Posts
    445
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    9

    Default

    not entirely

    how do you know it's group2 and group13 that have to be linked?

    if it's always the same, then
    Code:
    for group in group2 group13; do...
    Last edited by Watael; 16th November 2012 at 01:35 AM.
    A problem clearly stated is a problem half solved.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Linux Users Group
    By jaysunn in forum The Hangout
    Replies: 2
    Last Post: 27th January 2010, 05:10 PM
  2. how to add group of users from an input file
    By john23 in forum Shell scripting
    Replies: 1
    Last Post: 6th August 2008, 01:59 AM
  3. Putting multiple users in one group in one shot
    By hrishikesh in forum Shell scripting
    Replies: 2
    Last Post: 23rd June 2008, 07:41 PM
  4. Add multiple users to a group
    By chuckbeattie in forum Linux software
    Replies: 2
    Last Post: 2nd November 2007, 11:04 PM
  5. [Solved] Hard links / symbolic links - is this what I need?
    By DavidFox in forum Linux software
    Replies: 6
    Last Post: 25th June 2007, 05:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •