Shell Script To Record Terminal Desktop Sessions Under Linux or Unix Like Operating Systems

by on August 19, 2012 · 7 comments

A simple shell script wrapper to record current terminal session of a linux or unix desktop. This script act as a wrapper to recordMyDesktop command which produces a file that contains a video and audio recording of a linux desktop session. The default behavior of recording is to mark areas that have changed (through libxdamage) and update the frame. This wrapper gets current window name and remove window decoration.

  1.  
  2. #!/bin/bash
  3. # A simple shell script wrapper to record current terminal session of a linux
  4. # desktop. May work under other Unix like operating systems too.
  5. # Tested on RHEL 6.x, Debian 6.x, and Ubuntu Linux
  6. # ----------------------------------------------------------------------------
  7. # Written by Vivek Gite <http://www.cyberciti.biz/>
  8. # (c) 2012 nixCraft under GNU GPL v2.0+
  9. # ----------------------------------------------------------------------------
  10. # Last updated: 19/Aug/2012
  11. # ----------------------------------------------------------------------------
  12.  
  13. _xw=/usr/bin/xwininfo
  14. _recd=/usr/bin/recordmydesktop
  15. _awk=/usr/bin/awk
  16. _grep=/bin/grep
  17. _file="$1"
  18. _output=""
  19.  
  20. # change this to match your PS1 settings
  21. _regex='vivek@wks01: '
  22.  
  23. die(){
  24. echo -e "$1"
  25. exit ${2:9999}
  26. }
  27.  
  28. [ $# -eq 0 ] && die "Usage: $0 filename.ogv\n\nRecord terminal desktop sessions under Linux or Unix." 1
  29.  
  30.  
  31. # add extension .ogv if not given
  32. _ext="${_file%%.ogv}"
  33. [[ "$_ext" == "$_file" ]] && _output="$_file.ogv" || _output="$_file"
  34.  
  35. [ ! -x "$_xw" ] && die "Error: $_xw not found or set correct \$_xw in $0" 2
  36. [ ! -x "$_recd" ] && die "Error: $_recd not found or set correct \$_recd in $0" 3
  37. [ ! -x "$_awk" ] && die "Error: $_awk not found or set correct \$_awk in $0" 4
  38. [ ! -x "$_grep" ] && die "Error: $_grep not found or set correct \$_grep in $0" 5
  39.  
  40. #get terminal window id
  41. _id=$($_xw -root -tree | $_grep "$_regex" | $_awk '{ print $1}')
  42.  
  43. #get terminal windows x,y, width, and hight
  44. _x=$($_xw -id $_id | $_grep 'Absolute upper-left X' | $_awk '{ print $4}')
  45. _y=$($_xw -id $_id | $_grep 'Absolute upper-left Y' | $_awk '{ print $4}')
  46. _w=$($_xw -id $_id | $_grep 'Width:' | $_awk '{ print $2}')
  47. _h=$($_xw -id $_id | $_grep 'Height:' | $_awk '{ print $2}')
  48.  
  49. x=$(( $_x + 8 ))
  50. y=$(( $_y + 57 ))
  51. width=$(( $_w -31 ))
  52. height=$(( $_h -62 ))
  53.  
  54. $_recd --no-sound -x $x -y $y --width $width --height $height -o $_output
  55.  

How do I use this script?

  1. Open a terminal.
  2. Open Tab.
  3. Run script as:
  4. ./script.sh foo.ogv

  5. Switch to tab # 1 and run your command.
  6. When done switch back to tab #2 and press CTRL + C to save recording to foo.ogv.
  7. To run foo.ogv type:
  8. gnome-open foo.ogv
    OR
    mplayer foo.ogv



4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • Linver

    great!.

  • bemehow

    This is even better for the job :)

    http://ascii.io/

  • LittleBoy

    /usr/bin/xwininfo: error: -id requires argument
    /usr/bin/xwininfo: error: -id requires argument
    /usr/bin/xwininfo: error: -id requires argument
    /usr/bin/xwininfo: error: -id requires argument
    –width must be larger than 0.
    –height must be larger than 0.

  • LittleBoy

    usage: /usr/bin/xwininfo [-options ...]
    Got this message… Can you help please….

  • foobar

    Great script

  • Pradip Shah

    Is there a way to record a ssh session?

  • LifeShare

    Excellent. Thanks for sharing it,

Previous Script:

Next Script: