如果我理解正确, /etc/issue将通过agetty在控制台中显示
我想看到/etc/issue ,由agetty分析 – 但我不想开始任何login会话或任何相关的。 我只想要一个文件转储的/etc/issue – parsing命令。
这可能吗? 怎么样?
我不认为有一个效用会做你想要的。 查看agetty源代码函数do_prompt(…)基本上打开/ etc / issue文件并逐字符读取它,或者显示读取的字符,或者如果是\它读取下一个字符,然后input一个switch语句显示相关信息。 将其转换为脚本并不难…无论如何,这里是相关的代码
void do_prompt(op, tp) struct options *op; struct termios *tp; { #ifdef ISSUE FILE *fd; int oflag; int c; struct utsname uts; (void) uname(&uts); #endif (void) write(1, "\r\n", 2); /* start a new line */ #ifdef ISSUE /* optional: show /etc/issue */ if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) { oflag = tp->c_oflag; /* save current setting */ tp->c_oflag |= (ONLCR | OPOST); /* map NL in output to CR-NL */ (void) tcsetattr(0, TCSADRAIN, tp); while ((c = getc(fd)) != EOF) { if (c == '\\') { c = getc(fd); switch (c) { case 's': (void) printf ("%s", uts.sysname); break; case 'n': (void) printf ("%s", uts.nodename); break; case 'r': (void) printf ("%s", uts.release); break; case 'v': (void) printf ("%s", uts.version); break; case 'm': (void) printf ("%s", uts.machine); break; case 'o': { char domainname[MAXHOSTNAMELEN+1]; #ifdef HAVE_GETDOMAINNAME if (getdomainname(domainname, sizeof(domainname))) #endif strcpy(domainname, "unknown_domain"); domainname[sizeof(domainname)-1] = '\0'; printf ("%s", domainname); } break; case 'O': { char *dom = "unknown_domain"; char host[MAXHOSTNAMELEN+1]; struct addrinfo hints, *info = NULL; memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; if (gethostname(host, sizeof(host)) || getaddrinfo(host, NULL, &hints, &info) || info == NULL) fputs(dom, stdout); else { char *canon; if (info->ai_canonname && (canon = strchr(info->ai_canonname, '.'))) dom = canon + 1; fputs(dom, stdout); freeaddrinfo(info); } } break; case 'd': case 't': { /* TODO: use nl_langinfo() */ char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; time_t now; struct tm *tm; (void) time (&now); tm = localtime(&now); if (c == 'd') (void) printf ("%s %s %d %d", weekday[tm->tm_wday], month[tm->tm_mon], tm->tm_mday, tm->tm_year < 70 ? tm->tm_year + 2000 : tm->tm_year + 1900); else (void) printf ("%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); break; } case 'l': (void) printf ("%s", op->tty); break; case 'b': { int i; for (i = 0; speedtab[i].speed; i++) { if (speedtab[i].code == cfgetispeed(tp)) { printf("%ld", speedtab[i].speed); break; } } break; } case 'u': case 'U': { int users = 0; struct utmp *ut; setutent(); while ((ut = getutent())) if (ut->ut_type == USER_PROCESS) users++; endutent(); printf ("%d ", users); if (c == 'U') printf ((users == 1) ? _("user") : _("users")); break; } default: (void) putchar(c); } } else (void) putchar(c); } fflush(stdout); tp->c_oflag = oflag; /* restore settings */ (void) tcsetattr(0, TCSADRAIN, tp); /* wait till output is gone */ (void) fclose(fd); } #endif { char hn[MAXHOSTNAMELEN+1]; if (gethostname(hn, sizeof(hn)) == 0) write(1, hn, strlen(hn)); } (void) write(1, LOGIN, sizeof(LOGIN) - 1); /* always show login prompt */ }