LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-30-2012, 07: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, 08: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, 09: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, 10:01 PM   #4
casualfred
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Slackware
Posts: 97

Rep: Reputation: 27
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, 10: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, 10: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, 10: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, 10: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, 10: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, 12: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, 12: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, 07: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 07:49 PM.
 
Old 08-31-2012, 08: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, 09: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, 10: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



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

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

All times are GMT -5. The time now is 07:01 AM.

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