Veja / etc / issue conforme analisado por agetty

1

Se eu entendi corretamente, /etc/issue será mostrado no console por agetty

Eu gostaria de ver /etc/issue , conforme analisado por agetty - mas não quero iniciar nenhuma sessão de login nem nada relacionado a ela. Eu só quero um dump de texto de /etc/issue - com comandos analisados.

Isso é possível? Como?

    
por dangonfast 16.01.2013 / 23:24

1 resposta

2

Não acho que haja um utilitário que faça o que você deseja. Olhando para a fonte da agetty codificar a função do_prompt (...) basicamente abre o / etc / arquivo de assunto e lê isto caráter por caráter e ou exibe o caractere leu ou se é um \ lê o próximo char e então entra uma declaração de comutador para exibir a informação relevante. Não seria muito difícil converter isso em um script ... de qualquer maneira, aqui está o código relevante

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] = '
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] = '%pre%';
             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 */
}
'; 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 */ }
    
por 19.03.2013 / 23:26

Tags