LinuxQuestions.org
Help answer threads with 0 replies.
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, 11: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 11:59 PM.
 
Old 11-29-2011, 08:55 AM   #2
spiky0011
Senior Member
 
Registered: Jan 2011
Location: PLANET-SPIKE
Distribution: /LFS/Centos6.3/Debian
Posts: 2,127
Blog Entries: 1

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
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 12:18 PM.
 
Old 11-29-2011, 03:28 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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, 03:51 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

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


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


All times are GMT -5. The time now is 03:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration