1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Linux Ubuntu Hard-link for Every User

Discussion in 'Software' started by TheAbyssDragon, 21 Nov 2010.

  1. TheAbyssDragon

    TheAbyssDragon Gafgarion

    Joined:
    8 Dec 2005
    Posts:
    109
    Likes Received:
    0
    I would like to create the following hard-link for every one of my users (including root):
    Code:
    /storage/backups/%u     /home/%u/.backups    none    loop    0    0
    How can I generate all of these hard-links without hand coding them in fstab?

    My first thought was to use the pam_mount module, but most of my users don't even have shell access, so I don't think that would work. I'm thinking I may have to write a small script that just runs at boot.

    Thanks for any input.
     
  2. TheAbyssDragon

    TheAbyssDragon Gafgarion

    Joined:
    8 Dec 2005
    Posts:
    109
    Likes Received:
    0
    I ended up just writing a small bash script to run at boot time. The script parses the passwd file for users with UID >= 1000 (ie non-system users). Then for each user, pulls their home directory from the same file and mounts the backups folder if it exists.

    Code:
    #!/bin/bash
    
    # Mount root user's backup directory
    mount -o bind /storage/backups/root /root/.backups
    
    # Mount remaining users' backup directories
    USERS="$(awk -F ':' '{ if ( $3 >= 1000 ) print $1 }' /etc/passwd)"
    
    for u in $USERS
    do
            h="$(grep $u /etc/passwd | cut -d ':' -f 6)"
    
            if [ -d "$h/.backups" ]
            then
                    mount -o bind /storage/backups/$u $h/.backups
            fi
    done
     
  3. dinoscothern

    dinoscothern Minimodder

    Joined:
    16 Aug 2010
    Posts:
    132
    Likes Received:
    0
    Its probably the most practical way of doing things.
    I guess automount might be coerced into doing it automatically, but its probably not worth the bother.
     

Share This Page