LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-30-2012, 08:57 PM   #1
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Rep: Reputation: Disabled
Execute a script and not able to redirect to a file


Hi,

I am trying to execute a script. This scripts waits for commands from another console. I want to capture everything that will happen from this script.

I am using the following:
./script >> log.txt
cat log.txt


log.txt is empty.


If I use something like this:
ps >> log.txt , it works.


Thanks!
 
Old 08-30-2012, 09:48 PM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
What's the contents of script?
 
Old 08-30-2012, 10:33 PM   #3
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
The script's function is to execute abc.out. To simplify, abc.out has a bunch of questions and the user has to answer it.

Contents of the script:

pidof abc.out | xargs kill (find the pid and kill the process)
/programs/abc.out

The function of abc.out is:
abc.out asks the user many questions and the user replies to it.
abc.out waits for the inputs from the user.

If the script is to execute many commands without any user interaction the redirection to the file works but if its the case like above, the redirected file is empty.

Thanks!

P.S: Since I use Busybox, and there is no pidof, I somehow managed to do the equivalent of pid.
 
Old 08-30-2012, 11:01 PM   #4
casualfred
Member
 
Registered: Aug 2012
Location: USA
Distribution: Slackware64-14.2
Posts: 86

Rep: Reputation: 23
You could probably combine all of this into one script, if abc.out is also a script...
You could run something like this as a script maybe:
Code:
#!/bin/bash

echo "This is the answer log" > log.txt
echo "" >> log.txt

clear
echo This is question one?
read QONE
echo $QONE >> log.txt

clear
echo This is question two?
read QTWO
echo $QTWO >> log.txt

clear
echo This is question three?
read QTHREE
echo $QTHREE >> log.txt

clear
I don't know if this was actually what you were looking for, but it's just a thought
 
Old 08-30-2012, 11:07 PM   #5
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi Casualfred,

Thanks for your input. But abc.out does a lot more than just simple questions. It communicates between another console where it gets the input. So this has to be run by another script. And when I run this script I need to capture all the input/output from abc.out to a log file. Hence my question.

Thanks!
 
Old 08-30-2012, 11:37 PM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Does it work if you run it directly?
Code:
/programs/abc.out >> log.txt
I mean run it in an interactive shell, and not as wrapped in a script.
 
Old 08-30-2012, 11:39 PM   #7
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
No it doesn't. It's still the same issue. The script is just to kill the process before executing it.
 
Old 08-30-2012, 11:41 PM   #8
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by shisha View Post
No it doesn't. It's still the same issue. The script is just to kill the process before executing it.
I guess the problem lies on abc.out itself. Perhaps it makes an output to another virtual device e.g. /dev/stderr, /dev/vc/somewhere, etc.

Try
Code:
/programs/abc.out >> log.txt 2>&1
 
Old 08-30-2012, 11:45 PM   #9
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Or it doesn't create an output at all. Perhaps the application only creates an output on virtual terminals just for the sake of interaction. It doesn't open anything like files if it's not.
 
Old 08-31-2012, 01:10 PM   #10
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I tried the same but it doesn't work

Quote:
Originally Posted by konsolebox View Post
Or it doesn't create an output at all. Perhaps the application only creates an output on virtual terminals just for the sake of interaction. It doesn't open anything like files if it's not.
But I can see a lot of information coming up in my console.
 
Old 08-31-2012, 01:32 PM   #11
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
When I use the following:

Code:
./script & >> log.txt
cat log.txt
I am now able to execute the script but I get the following output :
Code:
[1] + Done                             ./script
 
Old 08-31-2012, 08:48 PM   #12
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by shisha View Post
When I use the following:

Code:
./script & >> log.txt
...
I didn't see you use "&" with script before.. Why run it in the background?

Last edited by konsolebox; 08-31-2012 at 08:49 PM.
 
Old 08-31-2012, 09:20 PM   #13
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
No I just wanted atleast the script to run while having the ">>" in my command. But I don't want it to run in the background.

Also, my task can also be implemented if I could capture everything that is going to happen right from logging into the console. Is there anyway to capture everything from log on. I will be continuously monitoring the log so that once I find a regex match I will have to run the script again. That has been my aim.

Thanks !
 
Old 08-31-2012, 10:58 PM   #14
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by shisha View Post
But I can see a lot of information coming up in my console.
Try running vim > out.txt. You'll notice that it would send a message like "Vim: Warning: Output is not to a terminal. This shows that an application could detect what its output device is like. Perhaps your application abc.out doesn't open any output at all if it's not a terminal. Could you examine the application directly, I mean examine its source code?
 
Old 08-31-2012, 11:15 PM   #15
shisha
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Busybox that I use doesn't support vim.
 
  


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
Redirect output of a command to another file inside shell script mukul_d Linux - General 4 08-27-2010 03:23 PM
trying to run a script in the background redirect the output to a file jdwalk Linux - Newbie 5 02-12-2010 08:50 AM
Unable to redirect script output to a file alien12 Linux - Newbie 4 08-25-2009 04:36 AM
cannot execute script file from shell shahrahulb Linux - General 4 03-04-2008 08:02 AM
how to execute a script file? Have file/directory not found error sirius57 Linux - Software 2 11-22-2007 12:43 AM

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

All times are GMT -5. The time now is 01:17 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