Script

From Physiki
Jump to: navigation, search

The script command in Linux can be very useful for logging the set of commands you do either for finding out exactly what you did or for logging students' usage of a terminal. However, the output encoding ends up spitting out a number of weird characters. This, unfortunately, is working as intended. Therefore, there are a few things that can be done to read it more cleanly.

Note that this will not copy passwords, as that does not show up in the terminal, it will show what you did through an ssh session, and it will NOT show you what you did through something like nano. If you are working with a number of files and editing them, I would recommend copying the file and using the diff command to create a patch file.

Contents

cat Command

Simply using cat to output the file works fine. All the coloring works and all the commands used work. I recommend using the option -n to view the file since it can very much just blend in with your own terminal session.

To be more complex, using
cat -n scriptfile | more
allows you to not only read the entire file with line numbers, but scroll through each page.

Running output through col

Simply running the file that you just created using script in the normal method through col will clean out most of the odd characters in the script file. This cleans up the file significantly, but makes it much more difficult to read through cat and coloring will still be messed up. Running the command
cat scriptfile | col -b > newfile
is the best way to clean it up, although whether you wish to do this method varies.

Modifying the shell when running

Running the following command seems to work for making a file that's easier to read in a standard text editor. However, your terminal prompt simply becomes a $, which, for those of you who are used to it show you what computer and what directory you're in, can be disorienting.

SHELL=/bin/sh PS1="$" script abc.log

less and more

less, with the options N (line numbers) and R (color formatting), will output the file in a manner that's readable, but leaves some of the "M^" characters in. This is, however, much better than reading it straight through something like nano.

more works well, formatting wise, but it might be nice to have line numbers still printed, so you can run
nl filename | more
which will then tack on line numbers to the script.

External Links

Running output through col

Shell modification page

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox