static void create_home (void) { if (access (user_home, F_OK) != 0) { #ifdef WITH_SELINUX selinux_file_context (user_home); #endif /* XXX - create missing parent directories. --marekm */ if (mkdir (user_home, 0) != 0) { fprintf (stderr, _("%s: cannot create directory %s\n"), Prog, user_home); #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_USER, Prog, "adding home directory", user_name, (unsigned int) user_id, SHADOW_AUDIT_FAILURE); #endif fail_exit (E_HOMEDIR); } chown (user_home, user_id, user_gid); chmod (user_home, 0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK)); home_added = true; #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_USER, Prog, "adding home directory", user_name, (unsigned int) user_id, SHADOW_AUDIT_SUCCESS); #endif #ifdef WITH_SELINUX /* Reset SELinux to create files with default contexts */ setfscreatecon (NULL); #endif } } int main(int argc, char *argv[]) { ................ create_home (); if (home_added) copy_tree (def_template, user_home, user_id, user_gid); else fprintf (stderr, _ ("%s: warning: the home directory already exists.\n" "Not copying any file from skel directory into it.\n"), Prog); ...................... }
前先不建/u01/oracle, 报错 是因为 if (mkdir (user_home, 0)) { 相当于没有参数 -p 的mkdir /u01/oracle
建了/u01/oracle 有useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件 是因为 if (access (user_home, F_OK)) { 这个 /u01/oracle目录已经存在
所以只有只指定不含子路径的时候才能没有警告出现
cp /etc/skel/.bash_profile /u01/oracle cp /etc/skel/.bashrc /u01/oracle cp /etc/skel/.bash_logout /u01/oracle
这样既可。