The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script running with "ksh" dumping core but not with "sh" simhe02 HP-UX 9 11-04-2008 08:52 PM
#!/bin/sh script fails at StringA | tr "[x]" "[y]" by_tg UNIX for Dummies Questions & Answers 3 02-22-2008 12:17 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
Q: Recording shell script screen output using "script" command ? lalfonso.gomez Shell Programming and Scripting 4 01-18-2007 09:31 PM
Help! "Put" command from telnet session tigote UNIX for Dummies Questions & Answers 5 12-27-2001 04:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-23-2004
mohanprabu's Avatar
mohanprabu mohanprabu is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 16
Exclamation "SCRIPT" (recording session) from ShellScripts

Hi all,

Hope that we are all familiar with the "script" command, which helps us to record the session into any file, until we give "exit".

Can anyone help me, how to do this process from a shell script!? I face problem while ending the script using "exit" which comes out of the program. This is what I coded (for eg., to record the listing command into tempfile.log):

script tempfile.log <<EOF
ls -ltr
exit
EOF

Is there any mistake!? I could smell something fishy, but unable to find it.

Thanks,
  #2 (permalink)  
Old 11-24-2004
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Since the script command would need to put info back to the screen, it may be a problem trying to force it into a file.

If you are looking to put the output of a command(s) into a file, just redirect for each command.
ls -ltr >> tempfile.log
pwd >> tempfile.log

Or you could invoke the script to dump output into the tempfile.log...
$ ./yourscript > ./tempfile.log
  #3 (permalink)  
Old 11-27-2004
kduffin's Avatar
kduffin kduffin is offline Forum Advisor  
UN1X
  
 

Join Date: Nov 2003
Location: Maryland
Posts: 449
Normally, when you use script it shows not just the output, but the commands that were run to get the output. Here's another alternative that won't require you to recode in order to print every command and its output.

Add the following to the top and bottom of your script:

Code:
set -x
...
set +x
When you run your script, use the 'tee' command and redirect stderr to stdout. For example, if I had some script called test.sh:

Code:
#!/bin/sh
# test.sh
set -x
echo hello
ls -ld /etc/hosts
echo goodbye
set +x
And I wanted everything that it did and saw outputed to test.log:

Code:
$ ./test.sh 2>&1 | tee test.log
+ echo hello
hello
+ ls -ld /etc/hosts
lrwxrwxrwx   1 root     root          12 Apr 17  2002 /etc/hosts -> ./inet/hosts
+ echo goodbye
goodbye
$ 
$ cat test.log
+ echo hello
hello
+ ls -ld /etc/hosts
lrwxrwxrwx   1 root     root          12 Apr 17  2002 /etc/hosts -> ./inet/hosts
+ echo goodbye
goodbye
$
Cheers,

Keith
  #4 (permalink)  
Old 11-27-2004
mohanprabu's Avatar
mohanprabu mohanprabu is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 16
Hi RTM, KDUFFIN!!

Thanks for ur suggestions. It was indeed a great help.. what kduffin said was something new...

RTM, what u suggest was great, but the code then becomes full of redirections...

The right code that helped me looks something like this:

sh <<EOF>>./output.log
ls -ltr
...
EOF

This was as per the suggestions from our moderator.

Thanks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0