LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: Disabled
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 :|)

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

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
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

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: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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