I have a bash script using dialog which basically just checks the status of certain services and displays it as either up or down. It works fine when I run it while logged in. I can't seem to figure out how to configure CentOS 7 to run this script and dialog when the system boots up. Ideally once CentOS finishes loading all services, instead of display the login prompt it'll just present this dialog to the user. My research seems to keep pointing at creating a service using systemd but I can't seem to find an example to fit my needs. Thanks in advance.

  • I don't remember if CentOS uses getty, but if it does, look at the getty services if you want to replace the login prompt. An example I wrote for Ubuntu: askubuntu.com/a/659268/158442 – muru Sep 23 '15 at 0:14
up vote 2 down vote accepted

Honestly, systemd services shouldn't be running interactive events. However, you should investigate the initial-setup-text.service, which does something like what you're asking for.

  • Do you suggest an alternative solution? My other thought was to create a user with minimal permissions and configure CentOS to autologin with this user account and then load the bash script and dialog this way. – Eric Person Sep 23 '15 at 2:10
  • After thinking through this some more, I decided to just run my script once the user logs in using .profile. Thanks for your help and suggestions. – Eric Person Sep 23 '15 at 15:52

I assume you're not using a GUI? And you want to display these results where the system login banner would normally go, just before the login prompt?

My first thought would be to add a service which depends on all the other services, and which writes to /etc/issue.

But if you want to do this "instead of" the login prompt, how will you log in?

  • Without knowing how to make this work, I would assume there would be a way to exit out of my dialog to be able to login or just alt f2 and login from there. – Eric Person Sep 23 '15 at 3:47

It won't look as pretty as dialog but you could write your script to add its results to /etc/issue so that it will be displayed immediately before the login: prompt.

The info will quickly become obsolete, though, so you should probably run the script from cron as well.

I'd suggest having some unique markers (before and after) your results message so that the cron job can search for and delete the old message before inserting the new.

Alternatively, have an /etc/issue.head and/or an /etc/issue.tail file to cat together with your results message.

For example:

myprog > /etc/issue.results
cat /etc/issue.head /etc/issue.results /etc/issue.tail > /etc/issue
  • BTW, most modern getty programs support ANSI escape sequences in /etc/issue and there are various tools (e.g. boxes) to generate nicely formatted boxed text etc from plain text input. – cas Sep 23 '15 at 5:08

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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