Urgent Help on "Script Command" on a shell script

Dear All,

I am trying to capture the terminal session using the script command. It works when i issue on that has a command. But it is not working on inside a shell script as it is expecting a exit command to come out. Even after I ran the script and it expects me type the exit command and not taking the exit command inside the script. This is urgent and can anyone help me ASAP.

This is the script I am using.

#!/bin/ksh
script
sleep 5
/sbin/initprivs
exit
exit

Hi.

Suppose your script is "s1". I would remove the command script from file "s1", then run as:

script -c ./s1

It looks like you may be running on SCO. I don't have access to that, however, my suggestion worked on a Linux box.

cheers, drl

1 Like

Hi,

Thanks for your response. I am running this on SCO UNIXWARE 7.1.3.

It does not have the option -c, I ran and got the following error.

root# script -c ./test1.ksh
usage: script [ -a ] [ typescript ]
root#

Please advice if there is any other way work it around on the script.

Regards,

Ravoi

I don't think that this can be done from a unix script. The "script" command intercepts commands typed from the keyboard and exits when it sees "exit" or ctrl/d. Even writing to the terminal device does not fool it.
An external workaround is to use a terminal scripting language such as that provided with WRQ Reflections (tm).

If all you want to do is record the output from the command (including error messages):

/sbin/initprivs 2>&1 >mylogfile

If you want to see what was output to standard output and record it:

/sbin/initprivs | tee mylogfile
1 Like

try

exit 0

1 Like

i tried both of you suggested but still I am unable to catch the ouput of it.

I am also checking if there is any other way of doing it.

Any other ideas / suggestions?

Hi.

Two possibilities, both of which might be a lot of work, both of which might not work:

1) Use expect, probably easy to install, requires tcl, but is not trivial to learn.

2) Download the package util-linux-ng from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/, which contains about 20 miscellaneous utilities, one of which is the version of script for Linux that I mentioned in an earlier post. All they supply is source, so you'd need to do the compile, etc. I'm using version 2.13.1.1, they are up to 2.18. I'm sure it could become very messy very quickly, trying to port from Linux to SCO.

Best wishes ... cheers, drl

Please show what you tried and what happened. Obviously "script" must not be running if you want to capture the output using shell commands.

script command will open a new shell and only when u type exit can it end .. i m not sure u can use the command like that inside the script .. if capturing the output and error of the commands fired is ur goal then why dont u use 2>&1 .. that should suffice ur need .

use bactics.

generally when you write in a script, you use them.

i am not sure if it will work but you may try that out.

Hi.

I tried solution # 2 in post # 7. The kernel.org command script did not compile on aix (a few errors with header files as I recall), whereas it did compile without errors on GNU/Debian Linux.

I don't have access to an SCO box, so I used aix simply because it was different from Linux, as SCO is different from Linux. The result was not totally unexpected, and was a good exercise. I did not investigate farther ... cheers, drl

Hi,

Thanks for all your inputs. I tried lot of things inside the shell script to use this script ( I cannot install any extra utilities on the boxes) but still looking for a exit from the shell prompt. So we decided to use some other methods.

Thanks for all your help.

Regards,

Ravi

Depending on your operating system you should try both :

a) /sbin/initprivs 2>&1 >mylogfile

b) /sbin/initprivs >mylogfile 2>&1

For example, i guess in HP-UX, the first one put the error into the log file which is what you may expect, but if you use Solaris, this will fail since the error has been sent to file descriptor 1 before it has been told to redirect into the log file : in Solaris, you should then use the way b).

Or just ...

/sbin/initprivs >initprivs.log 2>initprivs.err

you could either use | tee logfile or |tee -a logfile (fork the display to the logfile, 'a' stand for append)

After 5 months I cannot relate the most recent post to the original post (which was about the unix "script" command.

quite right, post closed...