LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Piping terminal output to another terminal (https://www.linuxquestions.org/questions/linux-newbie-8/piping-terminal-output-to-another-terminal-916119/)

Cyniikal 11-28-2011 10:57 PM

Piping terminal output to another terminal
 
Code:

#! /bin/bash

echo -n "File: ";read n;filename=$n
echo -n "Delay: ";read n;delay=$n
echo -n "Write to file? y/n: "read n

if [ "$n" = "y" ]
        then
                echo -n "What file do you want to write to?: "
                read n
                wfile=$n
        else
                echo "WARNING: If you are running this in another terminal, you will not receive output on deletion time. Unless you write to a file"
fi

if [[ -a $filename ]]
        then
                until [[ ! -a $filename ]]
                        do
                                echo "$filename exists"
                                sleep $delay
                        done
fi

[[ -a $filename ]] || output="$filename was renamed/removed at `date`";echo $output
if [ $wfile ];then echo $output >> $wfile;fi

now generally I would run this as "xterm -e monitor &" and whenever the script ends (Loop breaks) I would like it to output $output to the main terminal. Would knowing the PID of the terminal I want to pipe it to have something to do with this? Also any critiques on my script would be helpful.

(I use this script for Cyber-Patriot competitions where people are trying to break into the system and monitoring system files is very helpful, also the reason the script is spaced oddly is because im recreating it from memory, and im tired :|)

spiky0011 11-29-2011 07:55 AM

Not sure this is what you want With 2 terminals open an example
Code:

ls > /dev/pts/2
would output ls output to 2nd terminal

David the H. 11-29-2011 02:28 PM

A different option might be to run the script inside screen or a similar terminal multiplexer. Then you can access the same session from any terminal.

corp769 11-29-2011 02:51 PM

mkfifo also comes to mind; You can create a named pipe, and use tail or cat, or whatever else, to display the output in a different session.


All times are GMT -5. The time now is 10:25 PM.