"SCRIPT" (recording session) from ShellScripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "SCRIPT" (recording session) from ShellScripts
# 1  
Old 11-23-2004
Error "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  
Old 11-24-2004
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  
Old 11-27-2004
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  
Old 11-27-2004
Hi RTM, KDUFFIN!! Smilie

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.

ThanksSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

5. Cybersecurity

"authentication failure" then "session opened". Why?

Ssh connections using shared public keys issue “authentication failure” messages, then succeed with “session opened”. I have found a few other threads with similar issue, but no solutions offered. :wall: How can I eliminate the failure messages? Environment: $ uname -a Linux... (0 Replies)
Discussion started by: KennyCason
0 Replies

6. Linux

Session "hijacking" - Recover lost session

Hi Guys, Is there a way to recover a lost session? I was working in a server and that lost the connection, now, I have a new session but all the previous processes that I was running, like scripts, etc, are still running. Is there a way to bring them to my session? Best regards, Marco. (4 Replies)
Discussion started by: ocramas
4 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

Q: Recording shell script screen output using "script" command ?

Hello, I need to capture everything showed on a screen by a shell script which needs user interaction. The shell script performs commads such as rsh so normal redirection to a file does not work. I know there is a special unix command call "script" which records screen session but the... (4 Replies)
Discussion started by: lalfonso.gomez
4 Replies
Login or Register to Ask a Question