LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 09-16-2008, 08:39 AM   #1
scobiej
Member
 
Registered: Aug 2003
Location: London
Distribution: Redhat, SuSE, Ubuntu
Posts: 75

Rep: Reputation: 15
How to get the contents of a konsole session for scripting?


I appreciate this may be a security risk, but I cannot see a dcop call in konsole for actually accessing what is on the screen (in the buffer). I'd like to be able to direct a command to the konsole, which you can do, and scrape the results off so I can do other actions based on this output. I cannot do this directly using the running applications in that session.
Is there any way?
 
Old 09-17-2008, 05:46 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,738

Rep: Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550Reputation: 2550
'konsole' > > Edit > "Save history as"
will do the saving.

And another way : A lot of commands can save a text
by e.g. 'ls . > any_name.txt' or
'rpm -qa | sort > list_all_rpm.txt'

Regards
 
Old 09-17-2008, 10:24 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,040

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
Originally Posted by scobiej View Post
I appreciate this may be a security risk, but I cannot see a dcop call in konsole for actually accessing what is on the screen (in the buffer). I'd like to be able to direct a command to the konsole, which you can do, and scrape the results off so I can do other actions based on this output. I cannot do this directly using the running applications in that session.
Is there any way?
The obvious way would be to use a file to communicate with the parent process. I haven't konsole installed so I can't test, but if you have the means to launch "a given command" via dcop my guess is that you could do something like:

Code:
#!/bin/bash
# My bash script

dcop "my dcop path" "a given command > ~/ktmpfile 2>&1"
# or however dcop is used in this case, I hope you get the idea
mydcop_pid=$!
# do whatever else
wait $mydcop_pid
# continue with the stuff that needs the konsole output, you can
# get if from ~/ktmpfile if everything went ok
It's just an idea that might or might not be viable. But it's worth a try, I guess.
 
Old 09-19-2008, 07:03 AM   #4
mlp68
Member
 
Registered: Jun 2002
Location: NY
Distribution: Gentoo,RH
Posts: 328

Rep: Reputation: 31
You can also use the script utility to capture the whole output (and since commands get echoed, that means all of it). It's often used in a forensic investigation to preserve evidence, but it works nicely for your purpose, too.

Just do

script session.log

and all that goes on is logged. Break out with control-D to get back to the original shell.

Takes some cleanup later since all special chars and sequences to position the cursor etc get logged as well.

Also, for a quick "what did I just do?" kind of capture you can use
history 50 > history.log

to get the last 50 commands.

Hope it helps,
mlp
 
  


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
Output contents to file on server from konsole helptonewbie Linux - Networking 4 02-13-2007 05:00 PM
Konsole - which pseudo-tty per session? theNbomr Linux - Software 5 11-07-2006 04:39 PM
Change Konsole default Session name zmeda Linux - Newbie 3 08-05-2006 02:01 AM
Add Path for a KDE Konsole session mikegorb Linux - Newbie 2 09-24-2004 01:42 PM
switch user for the whole KDE session, not just the Konsole glock19 Linux - General 2 12-12-2001 02:31 PM


All times are GMT -5. The time now is 11:07 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration