Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-28-2011, 10:57 PM   #1
LQ Newbie
Registered: Nov 2011
Posts: 1

Rep: Reputation: Disabled
Piping terminal output to another terminal

#! /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" ]
		echo -n "What file do you want to write to?: "
		read n
		echo "WARNING: If you are running this in another terminal, you will not receive output on deletion time. Unless you write to a file"

if [[ -a $filename ]]
		until [[ ! -a $filename ]]
				echo "$filename exists"
				sleep $delay

[[ -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 :|)

Last edited by Cyniikal; 11-28-2011 at 10:59 PM.
Old 11-29-2011, 07:55 AM   #2
Senior Member
Registered: Jan 2011
Distribution: /LFS/Debian
Posts: 2,438
Blog Entries: 1

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Not sure this is what you want With 2 terminals open an example
ls > /dev/pts/2
would output ls output to 2nd terminal

Last edited by spiky0011; 11-29-2011 at 11:18 AM.
Old 11-29-2011, 02:28 PM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
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.
Old 11-29-2011, 02:51 PM   #4
LQ Guru
Registered: Apr 2005
Posts: 5,818

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Piping one terminal to another youngstorm Linux - General 2 08-30-2011 07:48 AM
Piping terminal results c0ld.3l3m3nt Linux - Newbie 2 01-14-2011 07:18 PM
c++ How to get terminal output Infasoft Programming 4 03-16-2009 03:49 PM
Redirect terminal output to file AND terminal shan Linux - General 3 09-29-2006 08:36 AM
Squid Output to the Terminal? mattsthe2 Linux - Networking 5 10-27-2005 02:02 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:31 PM.

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