Skip navigation
This discussion is archived

BASH script to determine most recent/used user account

1707 Views 4 Replies Latest reply: Nov 13, 2009 7:07 AM by Andrew Caldwell RSS
Andrew Caldwell Calculating status...
Currently Being Moderated
Nov 11, 2009 12:26 PM
Hi everyone,

I'm trying to patch a script I have to copy user data and set permissions accordingly. I'd like to have the script sense the most-logged-into user account and set permissions on the corresponding home folder, is there a way to do this in Tiger?

My next question is that these computers are being upgraded from Tiger to Leopard. Is there a way in Leopard to sense all existing user accounts (again in BASH), and set permissions on their corresponding home folders? That might be the best solution, and the easiest to implement.

TIA!
  • Antonio Rocco Level 6 Level 6 (10,095 points)
    Andrew

    You may find more help with this over on the AppleScript and Unix Forums:

    http://discussions.apple.com/forum.jspa?forumID=735
    http://discussions.apple.com/forum.jspa?forumID=724

    Tony
  • rccharles Level 5 Level 5 (5,115 points)
    You want to look into backup solutions. This is a common problem that other people have solved i would assume. Look around.

    You don't want to mess with user permissions 'cause your going to have to change them back and obviously the system will crash in the middle of this and the permissions will end up a mess.

    There is a way of running a program as root which means that you have access to all files.

    Robert
    iMac G3 600, Mac OS X (10.4.11)
  • Andbrowny Calculating status...
    Hi Andrew, not the prettiest piece of code but you could start with something like

    mostused=$(ac -p | awk '{print $1,$2}'| sort -k2| sed '$d'| tail -1| awk '{print $1})

    to get the most used account, and then something like this to follow

    chown -R $mostused /Users/$mostused
    depending on what exactly you want it to do.

    or for the second one you could try something like


    #!/bin/bash
    cd /Users
    for i in `ls |grep -v [.]` ; do
    echo /Users/"$i"
    #chown -R "$i" /Users/"$i"
    done

    Uncomment the chown line to get it to do something other than output to screen.
    Remember, backup and test thoroughly before using.

    Cheers
    iMac ; MacBook ; MacBook Pro ; Mac Pro ; XServe ;, Mac OS X (10.5.6), OSX Server ; .local AD ; WINXP/Vista via Parallels Mac OS X 10.5.x/10.4.x

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.