LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-19-2022, 07:07 PM   #1
SCerovec
Senior Member
 
Registered: Oct 2006
Location: Cp6uja
Distribution: Slackware on x86 and arm
Posts: 2,471
Blog Entries: 2

Rep: Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980
Post detect active ttys regardless if a process is attached to any.


This was off topic in requests for -current, so far we had few attempts be a close match but no cigar.

here mine:
Code:
#!/bin/bash

ps ax | grep -e " tty" | grep -v "grep" | awk '{print $2}'
Hope the other gentlemen (and ladies) chime in...

The issue is - we want to detect the running tty regardless if it has a process attached to it.
 
Old 01-19-2022, 07:30 PM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Code:
active_ttys () 
{ 
    { 
        ps -Nd -o tty | grep tty[0-9];
        sed -n '/tty[0-9]/ { s/^\(tty[0-9]*\)\(.*\)/\1/ ; p }' /proc/consoles
    } | sort
}
Best I can come up with.

This will assume that there's a controlling process on each tty (except /dev/console): which should be the case, but might not be.

For using in a loop in rc.font though, I'm feeling it's over-engineered, and best just left to hard-coded values on the for, but it'd look something like this:
Code:
#!/bin/sh
#
# This selects your default screen font from among the ones in
# /usr/share/kbd/consolefonts.
#

font='ter-v24b'

active_ttys()
{ 
  { 
    ps -Nd -o tty | grep tty[0-9]
    sed -n '/tty[0-9]/ { s/^\(tty[0-9]*\)\(.*\)/\1/ ; p }' /proc/consoles 
  } | sort
}

for vc in $( active_ttys )
do
  setfont -C /dev/$vc "$font"
done

Last edited by GazL; 01-19-2022 at 07:43 PM.
 
Old 01-19-2022, 07:34 PM   #3
SCerovec
Senior Member
 
Registered: Oct 2006
Location: Cp6uja
Distribution: Slackware on x86 and arm
Posts: 2,471

Original Poster
Blog Entries: 2

Rep: Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980
Did You account for TTY can be up to 63 there?
 
Old 01-19-2022, 07:49 PM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Yes, that should work. The only purpose of checking the first numeric char is to ensure that it doesn't match 'ttyS' devices.
 
1 members found this post helpful.
Old 01-20-2022, 08:44 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Actually, there's still a problem with this. It works after boot, but at the point rc.M calls rc.font, the getty processes haven't been started.

So, back to my first idea of just hard-coding the names of the ttys I want to set the font on.

The other alternative of course, is to just put a setfont in /etc/profile so that it happens at login.

Last edited by GazL; 01-20-2022 at 08:46 AM.
 
Old 01-20-2022, 05:55 PM   #6
SCerovec
Senior Member
 
Registered: Oct 2006
Location: Cp6uja
Distribution: Slackware on x86 and arm
Posts: 2,471

Original Poster
Blog Entries: 2

Rep: Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980
In fact the only place that decides where a login will run is inittab, right?

Where is the place the kernel console is pointed to a tty or serial port? Can we inhere that from dmesg?
 
Old 01-21-2022, 05:54 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Yes, the getty are started by inittab (unless its a systemd system of course). console is determined by console= kernel boot parameter.

I'm just going to KISS and hardcode 1-8 on the for loop and leave it at that.
 
Old 01-21-2022, 07:06 AM   #8
baumei
Member
 
Registered: Feb 2019
Location: USA; North Carolina
Distribution: Slackware 15.0 (replacing 14.2)
Posts: 365

Rep: Reputation: 124Reputation: 124
If you "hardcode 1-8" into a for-loop in /etc/rc.d/rc.font, then I hope you also put a 'comment' into /etc/inittab for subsequent sys-admins about the gotcha lurking...

Quote:
Originally Posted by GazL View Post
I'm just going to KISS and hardcode 1-8 on the for loop and leave it at that.
 
Old 01-21-2022, 07:46 AM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Whether a getty is running on it or not really isn't relevant here. What matters is which virtual consoles the admin/user wants the font applied to: which is handled by rc.font. So, no need for a comment in inittab; a comment in rc.font explaining should do the job.
 
Old 01-21-2022, 11:00 AM   #10
JMGonk
LQ Newbie
 
Registered: Aug 2021
Posts: 7

Rep: Reputation: Disabled
My take on it, not sure if it satisfies all requirements:
Code:
for i in $(awk '$1 ~ /^c[0-9]+:1?[2345]+:respawn:[^:]*getty$/ {print $(NF-1)}' /etc/inittab); do ls -l /dev/$i; done
You can also do away with the for loop and just make a system() call from within awk:
Code:
awk '$1 ~ /^c[0-9]+:1?[2345]+:respawn:[^:]*getty$/ {system("ls -l /dev/"$(NF-1))}' /etc/inittab
 
  


Reply

Tags
tty detection commandline



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can vim have tabs attached to viewports instead of viewports attached to tabs? frznchckn Linux - Software 0 11-17-2010 08:15 PM
detect process attached to devices linux_newbie79 Linux - Newbie 1 06-22-2009 06:56 AM
pl2303 attached to ttyUSB0 but driver attached to device is "serial" sheeluh Linux - Software 4 03-12-2007 04:27 AM
How can I say mouse is attached or not attached at the serial port ? lovelylinux Linux - Hardware 1 02-07-2007 09:44 AM
Serial Mouse is attached or not attached at seiral port lovelylinux Linux - Hardware 1 01-28-2007 07:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration