1831219 Members
2978 Online
110021 Solutions
New Discussion

script command usage

 
SOLVED
Go to solution
MikeL_4
Super Advisor

script command usage


Is there any way to force the script command to capture information to a file when a user executes a script??

We have cases were they are running a normal application script, and either not catching an error or something, but later on saying things didn't work right but have no information from the origional run.

Would like to force the script command to execute without them realizing it or having to do anything so I can check later on when they complain...
3 REPLIES 3
Helen French
Honored Contributor

Re: script command usage

You can actually redirect the standard output to a file:

# script_name > output_file_name
OR
# script_name > output_file_name 2>&1

If are talking about the 'script' command, you can capture the output like this:

# script file_name

Now, after this, whatever they type and the result will be stored on this file.
Life is a promise, fulfill it!
Sundar_7
Honored Contributor

Re: script command usage

Hi,

(

Script commands

) 1>/tmp/logfile 2>&1

Thanks,

Sundar
Learn What to do ,How to do and more importantly When to do ?
Bill Hassell
Honored Contributor
Solution

Re: script command usage

The easiest way is to trace the script every time they run it. To do that, use exec at the beginning to change stderr to a secret file and then start the script, something like this:

#!/usr/bin/sh
#
# log stderr here
# Use pid and username in filename

MYNAME=${0##*/}
MYUSER=$(/usr/bin/id -run)
exec 2> /var/tmp/$MYNAME-$MYUSER-$$.log
set -x

...rest of script...

Now the script works as before except every step is recorded in the file: scriptname-username-PID.log. Note that as with all scripts, set -x affects the current script and has no effect on functions nor will it report on what an external command might return.


Bill Hassell, sysadmin