Jump to content

Need a short script...


Recommended Posts

Hi guys!

 

I have a problem with disappearing terminal devices (the TTYxx) devices. Everytime I compile a program with my IDE one more device disappears. When they are all gone the compiler isn't invoked anymore from the IDE. Right now I have to reboot and hit the i option during boot to get the device nodes to be created again.

 

What I am looking for is a quick little script to run from root that will create the devices (so I don't have to reboot). The devices to be created are as follows:

 

crw-rw-rw- root tty 3, 0 ttyp0

crw-rw-rw- root tty 3, 1 ttyp1

crw-rw-rw- root tty 3, 2 ttyp2

.

.

.

crw-rw-rw- root tty 3, 15 ttypf

crw-rw-rw- root tty 3, 16 ttyq0

.

.

.

crw-rw-rw- root tty 3, 31 ttyqf

crw-rw-rw- root tty 3, 32 ttyr0

.

.

.

crw-rw-rw- root tty 3, 175 ttyzf

 

I don't know enough about the bash shell to create an iterative process to create the devices. Any help would be appreciated.

 

Glitz.

Link to comment
Share on other sites

Since I have no idea of how to create a /dev/tty (maybe tomorrow when I'll be not as tired as I'm now, I'll take a look to the man pages), I've searched a little bit on the web and I've found a script to create ttys.... what I've done with it are some modifications in order to fit your exact needs.

 

The makedev function makes a lot of sense to me, the only command I'm not familiar with is mknod; I'll check its man page tomorrow ;). IMHO this script must do what you want:

#! /bin/bash 

function makedev () { #params: tty_name [bc] major_n minor_n owner group mode

   [ -c $1 ] && rm -f $1

   mknod $1.tmp $2 $3 $4 &&

   chown $5:$6 $1.tmp &&

   chmod $7 $1.tmp &&

   mv $1.tmp $1

}

for i in p q r s t u v w x y z

do

   base=$(( $(expr pqrstuvwxyz : ".*$i" - 1 ) * 16))   

   for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f

   do

        n=$(expr 0123456789abcdef : ".*$j" - 1)   

        makedev /dev/tty$i$j c 3 $(($base+$n)) root tty 666

   done

done

exit 0

Hope this helps.

 

side note:

# the following code will be even simpler (but the one above is more robust)

function makedev() { 

... same as above

}

n=0

for i in p q r s t u v w x y z; do

   for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do

       makedev /dev/tty$i$j c 3 $n root tty 666

       n=$((n+1))

   done

done

 

(note: If you cut and paste the scripts make sure that no whitespace is appended at the end of each line... just to avoid some headaches)

 

edited: added the side note (and corrected some engilsh language errors)

Link to comment
Share on other sites

Thanks guys!!!

 

I'm using LM8.1 and makedev needs to be capitalized (ie. MAKEDEV). MAKEDEV also doesn't work properly (I had this problem before). It will create a device with a - after the name and then fail saying that the device could not be created do to permission problems. Anyway, to make a long story short I modified the script to use mknod as follows:

 

#!/bin/bash



n=0

for i in p q r s t u v w x y z; do

for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do

 mknod -m 666 /dev/tty$i$j c 3 $n

 chown root /dev/tty$i$j

 chgrp tty /dev/tty$i$j

 n=$((n+1))

done

done

 

It works like a charm. Thanks again.

 

Glitz.

 

PS. This scripting language has some powerful for loops.

Link to comment
Share on other sites

I don't know why they are disappearing. It may have something to do with the IDE I'm using. I use C-Forge and it has a built in terminal window that it spits compiler messages to. The window probably links to a TTY when it is active. Maybe there is a bug that deletes the TTY after. There are 176 ttys available so it takes a while to use them all up (ie. compile 176 times). It is an early MacMillan version of the program and I got it doubly cheap (~$10) since the store had it on sale. I really like the environment though. This version of C-Forge is taylored to C/C++, python, and tck/tk.

 

I'm currently developing a BASIC interpreter optimized for use in larger embedded systems (~128KB memory) that use a watchdog timer. I'm writing it in C for portability and easy customization to different platforms. It is designed for non-preemptive multitasking that is transparent to the BASIC program (ie. The program does not have to worry about multitasking at all, especially allowing other parts of the system to run) and that deterministically returns to the C main loop before the watchdog timer times out. I intend to use it for writing all the fiddly user interface code which I currently write as huge state machines in C (since in order to deterministically return to the main loop before the watchdog timer expires requires that I cannot wait in a loop or perform long computations all in one go). I could use pre-emptive multitasking which would relieve all my headaches but then there is no way to quickly and accurately determine if any given task has entered an infinite loop or is executing runaway code. And tickling the watchdog timer at more than one location in the program is bad practice.

 

Glitz.

Link to comment
Share on other sites

Speaking of cross platform portability and preemptive multitasking, were you also looking at Java to do this?

 

Also, wonder if you can make an inbetween script that checks your tty's and restores any missing one. A script that the IDE calls when it compiles? The script in turn would call the actual compilier and pass on the parameters. I'm assuming your IDE just calls a compilier and probably has a setup screen for it.

Link to comment
Share on other sites

Also, wonder if you can make an inbetween script that checks your tty's and restores any missing one. A script that the IDE calls when it compiles? The script in turn would call the actual compilier and pass on the parameters. I'm assuming your IDE just calls a compilier and probably has a setup screen for it.
It could be something as simple as this...

#!/bin/bash

n=0

for i in p q r s t u v w x y z; do

   for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do

       tty="/dev/tty$i$j"

       if [ ! -c ${tty} ]; then

           mknod -m 666 ${tty} c 3 $n && chown root:tty ${tty}

       fi

       n=$((n+1))

   done

done

# call the compiler here with the script's cmd_line args as the compiler args:

compiler $@

Glitz, notice that the use of the 'chgrp' command here is unnecessary as 'chown' is able to change both owner and group attributes at once.

Link to comment
Share on other sites

Speaking of cross platform portability and preemptive multitasking, were you also looking at Java to do this? 

 

Also, wonder if you can make an inbetween script that checks your tty's and restores any missing one. A script that the IDE calls when it compiles? The script in turn would call the actual compilier and pass on the parameters. I'm assuming your IDE just calls a compilier and probably has a setup screen for it.

 

Java is overkill considering the nature of the problem and the because there is no operating system and it would have to be completely taylored for the hardware. With the BASIC interpreter I hope to produce a small stand alone program that only requires hardware specific modifications in a few places. This does have to be bootable from a 32KB serial eeprom.

 

I have looked for any type of configuration settings that allow me to interpose a script that does some work before calling gcc. No luck. I will probably add the script to the rc.local startup script. That should be fine. I rarely have to recompile 176 times in one day :wink:

 

I really have to look into learning bash.

 

Glitz.

Link to comment
Share on other sites

I have looked for any type of configuration settings that allow me to interpose a script that does some work before calling gcc.  No luck.  I will probably add the script to the rc.local startup script.  That should be fine.  I rarely have to recompile 176 times in one day :wink:

 

I really have to look into learning bash.

 

Glitz.

well there are dozens of ways of achieving that :roll:, ie:

alias gcc=/path/tty_script.sh

remember that the script itself calls the compiler.

but you are right, 176 compilations in a day seems too much :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...