Bash: capturing *Anything* which showed on screen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash: capturing *Anything* which showed on screen
# 8  
Old 01-26-2011
Corona, methyl & citaylor Thank you very much.

@Crona:
Now I got what you mean and thanks for this valuable information.
So, I need some programming but between "expect" and "C Programming" I will choose the second one Smilie

@methyl:
You told that "CRT terminals in the 1980s were capable of repeating the screen output".
Could you please give me some more info about How they did that "repeating"?

@citaylor:
Yes, your answer was complicated but at last I figured it out Smilie
And many thanks for that "pseudoterminal (pty)" hint, I read the code before but I didn't get that ponit.

---------- Post updated at 11:06 AM ---------- Previous update was at 10:57 AM ----------

P.S: I'm going to build a simple remote system manager which will acts as a remote desktop but in text-mode. The difference is: Administrator from a single screen can connects, monitor and interact with N (>100) machines simultaneously.
So, It would not be a keylogger, password cracker or virus!!!
# 9  
Old 01-26-2011
Quote:
Originally Posted by siavash
@Crona:
Now I got what you mean and thanks for this valuable information.
So, I need some programming but between "expect" and "C Programming" I will choose the second one Smilie
There is a version of Expect for Perl too if you are more familar with that...

Quote:
Originally Posted by siavash
P.S: I'm going to build a simple remote system manager which will acts as a remote desktop but in text-mode. The difference is: Administrator from a single screen can connects, monitor and interact with N (>100) machines simultaneously.
Have you investigated the command "screen" at all ? Might give you some ideas...

Good luck
This User Gave Thanks to citaylor For This Post:
# 10  
Old 01-26-2011
Quote:
Originally Posted by citaylor
Have you investigated the command "screen" at all ? Might give you some ideas...
yes, a little. but I will check it again if you think that would be helpful... Smilie
# 11  
Old 01-26-2011
Quote:
@methyl:
You told that "CRT terminals in the 1980s were capable of repeating the screen output".
Could you please give me some more info about How they did that "repeating"?
One example of many was the DEC VT102 VDU Video Display Terminal Information ? VT100.net. It had a serial cable to the computer (or modem) and a serial output port for a printer. It was possible to pass control codes to the terminal to cause data to go to the printer or the screen or both. The feature is known as "passthru" and still exists in some modern terminal emulators. Most modern terminal emulators actually emulate the DEC vt220 which has a similar keyboard layout to a modern PC keyboard.

Attachmate Reflections unix terminal emulator includes a feature to log screen output to a file. The product also includes a keyboard scripting language where you can do "one button" full sessions.
# 12  
Old 01-26-2011
Quote:
Originally Posted by citaylor
If another program opened /dev/tty and started trying to do I/O through it, the shell would probably quit out or get arsey.
Nothing bad happens with trivial examples.
Code:
$ cat /usr/share/dict/cracklib-small > /dev/tty
10th
1st
2nd
3rd
4th
...
zoroaster
zounds
z's
zucchini
zurich
zygote
$ read VAR < /dev/tty
asdf
$ echo $VAR
asdf
$cat < /dev/tty
asdf
asdf
qwertyuiop
qwertyuiop
^D
$

And almost nothing bad happens with non-trivial examples:
Code:
$ cat /lib/libc.so.6 > /dev/tty
<unending pages of garbage>
$ 6;92;c^C
$ nano > /dev/tty < /dev/tty 2> /dev/tty
(normal nano behavior)
$

Which makes sense when you think about it. (nearly) any program run by the shell runs gets direct read/write access to the terminal from the get-go anyway -- if your program gets access to the terminal at all, the shell can't intermediate how you talk with it. Programs deal with the terminal direct. Reopening the terminal device isn't really different from the access you'd get from the first.

Now if that program started altering terminal settings out from under the shell that might be a different matter -- except the shell also runs programs that alter terminal settings all the time: Interactive editors, less, top, and others. The shell's expected to not go weird when running these. As long as they politely leave the terminal as they found it when they're done, nothing explodes. Even when they don't, reset\n is usually enough to put things where they belong.

In many shells, it's actually switching terminal modes by itself all the time -- putting the terminal into canonical mode whenever you run something, and switching back to non in order to process raw keystrokes. Any shell that lets you edit the commandline in a vi or emacs like fashion does this.

Finally:
Code:
$ ssh some.server.or.other > /dev/null 2> /dev/null < /dev/null
Password:

It's able to prompt me for a password with no open references to the terminal at all! When I strace it and grep for /dev/tty, it finds this:
Code:
open("/dev/tty", O_RDWR)                = 5

So ssh is quite prepared to go to the source when no other means is available.

(on further checking: In fact it seems to do so even when other means are available.)

Last edited by Corona688; 01-26-2011 at 10:45 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with bash escaping while using screen command

Hello, everyone. I'm currently trying to write a command system for a Minecraft server using screen. Here are the scripts I'm currently using. 0.sh #!/bin/bash screen -S Test114 -dm java -Xmx4G -jar server.jar nogui 1.sh #!/bin/bash args="$@" args2="${args@Q}" #args3=`printf '%q\n'... (2 Replies)
Discussion started by: Develon
2 Replies

2. UNIX for Dummies Questions & Answers

The block size in my quota is showed wrong

The block size in my home directory is showed wrong when I use "quota" command. It shows I use 1.2 gb ( about 1200000) while the real size in my directory which I use "du" command is 96 MB I really confused. (0 Replies)
Discussion started by: thsecmaniac
0 Replies

3. Red Hat

command line tool to disable screen lock and/or screen saver

Hi, I have a simple question : how to disable screen lock and/or sreen saver with command line with RHEL5.4 ? (1 Reply)
Discussion started by: albator1932
1 Replies

4. Programming

this code for addind polynomials using linked lists showed segmentation error..any help pls..

the error occurs in the function() "add" used... #include<stdio.h> #include<malloc.h> struct node { int exp; int coef; struct node * link; }; struct node * create_list(struct node *,int,int); void display(struct node *); struct node * add(struct node *,struct node *); ... (3 Replies)
Discussion started by: mscoder
3 Replies

5. Shell Programming and Scripting

Run a bash script, display on the screen and save all information in a file including error info

Hi all, How to: Run a bash script, display on the screen and save all information in a file including error information. For example: I have a bash script called test.sh now I want to run the test.sh and display the output on the screen and save the output including error info to a file. ... (1 Reply)
Discussion started by: Damon sine
1 Replies

6. Shell Programming and Scripting

Clear Screen Command for BASH shell

I am unable to use clear or cls command on bash shell. I have recently installed Cygwin and am using that for practicing unix commands. I see that I can use Ctrl + L to clear the screen. I created an alias in my .bashrc to do the same as alias cls='^L' This is how i defined other aliases ... (4 Replies)
Discussion started by: erora
4 Replies

7. Shell Programming and Scripting

Bash script [Press Tab] Screen Blank..

Dear Member, OLD Question --> disable-completion not solved My bash Menu script ping process problem. If ping still running and users press SCREEN is Blank... Cant Members help me.. kill signal or others scripting for my case, btw i use Linux.. Thanks, Rico My Bash Script : ... (1 Reply)
Discussion started by: carnegiex
1 Replies

8. Shell Programming and Scripting

Logging ALL standard out of a bash script to a log file, but still show on screen

Is it possible to store all standard-out of a bash script and the binaries it calls in a log file AND still display the stdout on screen? I know this is possible to store ALL stdout/stderr of a script to a single log file like: exec 1>&${logFile} exec 2>&1 But running a script with the... (3 Replies)
Discussion started by: ckmehta
3 Replies

9. AIX

used PPs not match the total disk space showed by df

Hi, I see from lsvg the total used PPs is 1050 (67200 megabytes), but when I check the disk space with df command I can only see 31G total space, can somebody tell how this come? Thanks! Victor # lsvg rootvg # lsvg rootvg VOLUME GROUP: rootvg VG IDENTIFIER: ... (2 Replies)
Discussion started by: victorcheung
2 Replies

10. Shell Programming and Scripting

Bash overwrites data on screen!!

hi everybody, when i run and compile this: printf("test"); fflush(stdout); nothing appears on screen. if i try this: ___________________________________ printf("test"); fflush(stdout); sleep(10); ___________________________________ then i can see the output "test"... for 10... (4 Replies)
Discussion started by: brain_processin
4 Replies
Login or Register to Ask a Question

Featured Tech Videos