LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-26-2003, 08:43 PM   #1
lmcthbe
LQ Newbie
 
Registered: May 2003
Location: Montreal
Distribution: RH 8.0
Posts: 4

Rep: Reputation: 0
Angry scripting the unix command script


I tried to use in a bash script, the unix command script (to log all input/ouput from the shell)

#!/bin/bash

script toto.txt
ls
exit

The script command is executed but nothing happend after unless 'exit' is typed to stop the script command then ls is executed.

The unix command script seems to open a second bash shell (pts/2) where I guess the ls command has to be executed but I didn't have found a way to do it???

Any help would be great

Thierry
 
Old 05-26-2003, 08:56 PM   #2
tangle
Senior Member
 
Registered: Apr 2002
Location: Arbovale, WV
Distribution: Slackware
Posts: 1,761

Rep: Reputation: 78
You can hit control and d key at the same time to stop the script command. Is that what you are asking?
 
Old 05-26-2003, 09:09 PM   #3
lmcthbe
LQ Newbie
 
Registered: May 2003
Location: Montreal
Distribution: RH 8.0
Posts: 4

Original Poster
Rep: Reputation: 0
No.

Better explanation, from the shell when the following is done:

%script toto.txt
Script started,.....
%ls
file1.txt file2.txt
%exit
Script ended
%more toto.txt
ls
file1.txt file2.txt
exit
%

toto.txt contains the ls command and the result printout

When I want to script that to get the same result

#!/bin/bash
script toto.txt
ls
exit

I have to do ctrl-d to stop the script command then ls is executed and toto.txt is empty.
 
Old 05-26-2003, 09:34 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If the only thing you need "toto.txt" to contain is the output from the "ls" command, then you could just pipe the output from "ls" to a file.
Else you could tell us why you need the "ls" command line to be there as well.
 
Old 05-27-2003, 08:35 AM   #5
lmcthbe
LQ Newbie
 
Registered: May 2003
Location: Montreal
Distribution: RH 8.0
Posts: 4

Original Poster
Rep: Reputation: 0
I used ls as an example in fact I am writing a script to perform regression testing of software build that happend each week.

Instead of running all the test by hand I wrote a script (that call each test case around 20) and I want to log what happend to be able to verify if any test failed (each testcase execution takes around 5 mn).

The script looks more like this:

script toto.txt
testcase1
testcase2
testcase3
......
testcase20
exit

Each testcase command gave on the shell a result printout (failed or passed)

I have found also that I could use the tee command like:

source mybashscript | tee toto.txt

but it would be more elegant to use the script command instead.

If it could not work too bad I will stick with tee!!!!
 
Old 05-27-2003, 09:58 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I just don't think using "script" is the right way, it's sposed to be an interactive tool. Why not "set -x" and pipe the output to a log, verify a test failed using exit status and on that basis parse logs?
Ridiculous example (but that's my approach):
logf="${__tmpdir}/$1.log"
parseLog() { grep "${logf}" <something>; do somethingElse; }
parseExit() { case $1 in 0) printf "%sOK\n";;
*) printf "%sFAILED\n"; parseLog;; esac; }
activate() { printf "%sActivating $1 "; set -x; $1 2>&1 "${logf}";
parseExit $?; set +x; }
for i in $(seq 0 2); do activate testcase${i}; done
# testcase? need to be functions within this script or sourced

Hope you get my point.
 
Old 05-27-2003, 07:52 PM   #7
lmcthbe
LQ Newbie
 
Registered: May 2003
Location: Montreal
Distribution: RH 8.0
Posts: 4

Original Poster
Rep: Reputation: 0
I got your point and I will look at the example that you gave.

I have to admit that it is a bit advance to me, I have started to do bash scripting monday. But I understand the concept!!

I didn't think to make the script to verify automaticaly the result of each testcases but this is a good idea.

Thanks for your help
 
Old 05-28-2003, 02:49 PM   #8
imroy
LQ Newbie
 
Registered: May 2003
Location: Australia
Distribution: Debian
Posts: 8

Rep: Reputation: 0
Just pipe the commands to script:

echo "ls" | script toto.txt

for longer bits I'd suggest something like:

script toto.txt << EOF
ls
df
du
EOF

but it doesn't seem to work as expected. Anyway, hopefully this will help a little.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux to train team members in UNIX scripting bogsdb Linux - Software 4 10-27-2004 05:42 AM
Unix Shell Scripting, detecting the enter key WinterSt Programming 7 09-01-2004 08:27 AM
unix scripting lapthorn Programming 7 03-11-2004 09:03 AM
php and unix scripting murshed Programming 3 06-26-2003 03:56 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 06:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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