2013-03-22 37 views
6

每次添加新用户时执行命令的最简单方法是什么?每次创建新用户时执行shell脚本

我通过/etc/adduser.conf检查,但没有看到它会做到这一点?

我想过把它添加到用户.bashrc所以当他们登录它仅仅指刚执行,但我宁愿把它设置他们在登录之前。

任何帮助,将不胜感激。

+0

如果你想让它在登录shell上运行,'.bash_profile'是放置它的地方。如果将它放在'.bashrc'中,它会在启动非登录shell时运行(如果'.bash_profile'包含'.bashrc'则在登录shell中运行)。 – Inductiveload 2013-03-22 10:31:38

+0

@lnductiveload这就是......这些脚本只会在新用户实际登录时运行 - 我希望在添加新用户后立即运行脚本。 – bsmoo 2013-03-22 10:35:21

回答

10

man adduser

If the file /usr/local/sbin/adduser.local exists, it will be exe‐ 
    cuted after the user account has been set up in order to do any 
    local setup. The arguments passed to adduser.local are: 
    username uid gid home-directory 

看起来你可以在这里添加用户创造行为。

+1

rtfm的另一种情况!谢谢你的帮助。 – bsmoo 2013-04-04 22:31:43

+0

你也可能想'chmod + x adduser.local'。 – e9t 2016-03-15 11:20:45

0

我不知道直接的方式...... 但是,你可以检查/etc/passwd文件或/home directrory变化,例如使用inotifywait或使用一些cron作业。

0

我在几年前编写了一个自定义脚本,并且在脚本中调用adduser来将用户添加到系统中。