Simply question about capturing output to /dev/tty

Suppose another person wrote the following one-line shell script:

echo $RANDOM > /dev/tty

QUESTION #1: How can the random number, which is output to the terminal by this script, be captured in a variable?

QUESTION #2: How can this be done in a cron job?

Specific code, whether in ksh or C, would be greatly appreciated.

---------------------------------------------------------------------

REAL LIFE STORY: We use software with concurrent licenses, which are managed on a UNIX server. The vendor supplies a program which simply displays the number of licenses currently being used, but it directs the output to /dev/tty (not stdout/stderr/file), and it is a compiled program so it cannot be directly altered using sudo permissions. I can only assume that the vendor is actively trying to prevent their customers from gathering statistics about their concurrent license usage, because the customer might find out they don't need so many licenses, contract for fewer licenses, and thus the vendor would loose money. :mad: The vendor has to provide some mechanism for determining license usage, but it's extremely limited. :frowning: I would like to gather statistics every 15 minutes, find the maximum concurrent license usage, so we can contract to the vendor for the ideal number of licenses. :smiley: Any help you can provide would be greatly appreciated. Thanks! --Paul.

You could use script:

script -q ksh -c 'echo $RANDOM > /dev/tty' > random_value
cat random_value

or gnuscreen:

screen -dmS getlicense ksh
screen -p 0 -S getlicense -X log on
screen -p 0 -S getlicense -X stuff 'echo \$RANDOM > /dev/tty\n'
sleep 1
screen -p 0 -S getlicense -X log off
screen -p 0 -S getlicense -X quit
cat screenlog.0