Results 1 to 7 of 7

Thread: "script" Command Problem

  1. #1
    Join Date
    May 2010
    Location
    Vicenza, Italy
    Posts
    23

    Question "script" Command Problem

    Anyone know how to make the output of command
    Code:
    # script
    show standard text as seen on the actual CLI? I'm trying to log my bash sessions so that if I run into problems I can easily copy and paste my i/o to forums or my blog but when I open up the created .txt files I'm seeing what I assume are codes for keystrokes. I'll give an example:
    Code:
    # script -a "/srv/Server/bashscripts/test1.txt"
    Script started, file is /srv/Server/sashscripts/test1.txt
    # echo "Hi there, this is just a test"
    Hi there, this is just a test
    # exit
    Script done, file is /srv/Server/bashscripts/test1.txt
    shows an output of:

    Script started on Sun Aug 21 22:51:25 2011
    [1m[31mlinux-ki7e:/dev # [0;10mecho "Hi there, this is just a test"
    Hi there, this is just a test
    [1m[31mlinux-ki7e:/dev # [0;10mexit

    Script done on Sun Aug 21 22:51:38 2011

    when I open up test1.txt. I thought maybe it was because I'm outputting to a text file (I'm viewing the files from a Windows box on my network) but outputting to an extension-less file returns the same thing. I've looked through the man pages for "script" but it says nothing about this. Is there a way to make it return characters as displayed? Am I making a mistake that is causing this to happen? Any advise would be much appreciated!
    Learning openSUSE
    http://part-time-nerd.blogspot.com/

    Server - openSUSE 11.4, Asus KGPE-D16 Motherboard, 12x 4GB RDIMM, 2x AMD Opteron 6128, OCZ 30GB SSD (OS), Adaptec Raid 5805Z running 6x Seagate 2TB Barracuda XT in RAID 5 (/srv)

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: "script" Command Problem

    It is what is displayed. script captures everything that goes to the tty, including any terminal control characters. Those [1m, etc are ANSI escape sequences. You also get the CRs at the ends of lines in the file.

  3. #3
    Join Date
    May 2010
    Location
    Vicenza, Italy
    Posts
    23

    Default Re: "script" Command Problem

    So is there a quick way to weed them out? I've been messing around with
    Code:
    # tr
    with no luck yet...
    Learning openSUSE
    http://part-time-nerd.blogspot.com/

    Server - openSUSE 11.4, Asus KGPE-D16 Motherboard, 12x 4GB RDIMM, 2x AMD Opteron 6128, OCZ 30GB SSD (OS), Adaptec Raid 5805Z running 6x Seagate 2TB Barracuda XT in RAID 5 (/srv)

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: "script" Command Problem

    You could set your terminal type within the script session to the dumbest possible one, but you'd still get things like backspaces and CRs. You might be able to remove those with judicious use of col and tr.

  5. #5
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,875
    Blog Entries
    3

    Default Re: "script" Command Problem

    If you display that output in a terminal, then those sequences are probably interpreted by the terminal and should display okay.

    I normally use "less" in an xterm to look at "typescript" files.
    openSUSE Leap 15.1; KDE Plasma 5;
    testing Leap 15.2Alpha

  6. #6
    Join Date
    May 2010
    Location
    Vicenza, Italy
    Posts
    23

    Default Re: "script" Command Problem

    Very true, but I'm trying to access the file via Windows in the form of a .txt so I can just copy and paste my commands into a browser. I think I'm going to end up writing a bash script to do this but to be honest I'm not familiar enough yet with that process to know where to begin. I've just started reading the Linux Command Line and Shell Scripting Bible though so hopefully soon I'll feel confident enough to do this.
    Learning openSUSE
    http://part-time-nerd.blogspot.com/

    Server - openSUSE 11.4, Asus KGPE-D16 Motherboard, 12x 4GB RDIMM, 2x AMD Opteron 6128, OCZ 30GB SSD (OS), Adaptec Raid 5805Z running 6x Seagate 2TB Barracuda XT in RAID 5 (/srv)

  7. #7
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,875
    Blog Entries
    3

    Default Re: "script" Command Problem

    The strange characters that are in the "typescript" file are escape characters. The definition of the escape characters depends on the terminal characteristics. They are probably for either type "xterm" or type "linux", as set by $TERM in the session where script was run. When you use "less" as suggested, that has access to the same terminal characterists table for interpreting the escape characters. There are probably sed scripts available that just strip them out, at least for variants of the "vt100" and "ansi" terminal definitions.

    The easiest thing would have been to browse the typescript file while still running linux, then while browsing use copy/paste to copy into a plain text file that you could then use on Windows.

    On the other hand, there is probably a "less" available for Windows, though that might require installing CYGWIN.
    openSUSE Leap 15.1; KDE Plasma 5;
    testing Leap 15.2Alpha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •