Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to be able to run a bash script every time a specific user logs in. The solution here is for all users.

Is there any way to specify the user, and if not is there a way for the bash script to check the username that has logged in?

share|improve this question

2 Answers 2

You can add a script call in his specific ~/.bashrc or ~/.bash_profile.

If you want it to be more general, you can add it in /etc/profile and check the username.

share|improve this answer
    
This only gets run if the user opens a shell; since this is OS X, most users will never do this... –  Gordon Davisson May 27 '13 at 17:23

If you go with the LaunchAgent solution, just put it in that user's ~/Library/LaunchAgents folder, and it'll only run when that particular user logs in.

If you go with the LoginHook solution, you need to write the script so that it checks the username (passed to the script as $1):

#!/bin/bash
if [ "$1" = "fred" ]; then
    # do stuff that only applies to fred
fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.