How to record/save your terminal activity

If you want to save your terminal activity on server for future use? It can be done using a script, whenever if you sign in to server via putty/terminal, just run the script command, it will automatically record the current activity. Finally, exit the script command that’s it.By default settings, script get installed in all servers.

1) Find script command installed or not in server ?

Use the below command to find whether the package is installed or not.

root@cpanel [/]# yum list installed | grep util-linux-ng
util-linux-ng.x86_64 2.17.2-12.24.el6

The output clearly shows script package is already installed on server.

2) How to start the script command ?

Just type script in terminal that’s it. The script command is started

root@cpanel [~]# script
Script started, file is typescript

3) How to do some activity in terminal ?

Here i’m going to do some activity in my terminal to check whether its working properly or not.

root@cpanel [~]# ls -lsa
total 15380
4 dr-xr-xr-x 32 root root 4096 Aug 19 08:08 ./
4 dr-xr-xr-x 32 root root 4096 Aug 19 08:08 ../
4 -rw------- 1 root root 1675 Mar 7 2015 anaconda-ks.cfg
4 -rw-r--r-- 1 root root 1941 Mar 13 2015 atiq.txt
0 -rw-r--r-- 1 root root 0 Jul 7 04:12 .autofsck
0 -rw-r--r-- 1 root root 0 Mar 7 2015 .autorelabel
4 dr-xr-xr-x 2 root root 4096 Aug 12 19:26 bin/
4 dr-xr-xr-x 5 root root 4096 Aug 19 02:00 boot/
4 drwxr-xr-x 2 root root 4096 Mar 23 08:05 cgroup/
28 -rw-r--r-- 1 root root 27070 Jan 30 2015 cldeploy
4 drwxr-xr-x 4 root root 4096 Mar 7 2015 cpanel3-skel/
4 -rw-r--r-- 1 root root 520 Jan 8 2013 cpanel-install
0 drwxr-xr-x 17 root root 6220 Aug 19 02:25 dev/
116 -rw-r--r-- 1 root root 113333 Aug 16 02:19 error_log
16 drwxr-xr-x 107 root root 16384 Aug 19 08:06 etc/
11908 -rw-r--r-- 1 root root 12193269 May 9 19:25 ffmpeg-strace
4 drwx--x--x 103 root root 4096 Aug 19 07:54 home/
4 drwxr-xr-x 2 root root 4096 Feb 7 2016 home2/
4 -rwxr-xr-x 1 root root 3262 Mar 8 2015 installcpan.sh*
4 -rw-r--r-- 1 root root 10 Mar 7 2015 installer.lock
16 -rw-r--r-- 1 root root 14772 Mar 7 2015 install.log
4 -rw-r--r-- 1 root root 3858 Mar 7 2015 install.log.syslog
4 drwxr-xr-x 2 root root 4096 Jan 30 2014 ioncube/
4 dr-xr-xr-x 8 root root 4096 May 25 08:08 lib/
12 dr-xr-xr-x 9 root root 12288 May 25 08:09 lib64/
16 drwx------ 2 root root 16384 Mar 7 2015 lost+found/
4 drwxr-xr-x 2 root root 4096 Jul 20 2011 media/

4) How to exit the script command ?

Just type exit in terminal that’s it. The script command is closed.

root@cpanel [~]# exit
exit
Script done, file is typescript

5) I’m going to check the recorded/saved contents ?

You can use any text editor or cat or more command to check the recorded/saved contents on typescript file.

more typescript
Script started on Fri 19 Aug 2016 08:08:39 AM CEST
root@cpanel [/]# ls -lsa
total 15380
4 dr-xr-xr-x 32 root root 4096 Aug 19 08:08 ./
4 dr-xr-xr-x 32 root root 4096 Aug 19 08:08 ../
4 -rw------- 1 root root 1675 Mar 7 2015 anaconda-ks.cfg
4 -rw-r--r-- 1 root root 1941 Mar 13 2015 atiq.txt
0 -rw-r--r-- 1 root root 0 Jul 7 04:12 .autofsck
0 -rw-r--r-- 1 root root 0 Mar 7 2015 .autorelabel
4 dr-xr-xr-x 2 root root 4096 Aug 12 19:26 bin/
4 dr-xr-xr-x 5 root root 4096 Aug 19 02:00 boot/
4 drwxr-xr-x 2 root root 4096 Mar 23 08:05 cgroup/
28 -rw-r--r-- 1 root root 27070 Jan 30 2015 cldeploy
4 drwxr-xr-x 4 root root 4096 Mar 7 2015 cpanel3-skel/
4 -rw-r--r-- 1 root root 520 Jan 8 2013 cpanel-install
0 drwxr-xr-x 17 root root 6220 Aug 19 02:25 dev/
116 -rw-r--r-- 1 root root 113333 Aug 16 02:19 error_log
16 drwxr-xr-x 107 root root 16384 Aug 19 08:06 etc/
11908 -rw-r--r-- 1 root root 12193269 May 9 19:25 ffmpeg-strace
4 drwx--x--x 103 root root 4096 Aug 19 07:54 home/
4 drwxr-xr-x 2 root root 4096 Feb 7 2016 home2/
4 -rwxr-xr-x 1 root root 3262 Mar 8 2015 installcpan.sh*
4 -rw-r--r-- 1 root root 10 Mar 7 2015 installer.lock
16 -rw-r--r-- 1 root root 14772 Mar 7 2015 install.log
4 -rw-r--r-- 1 root root 3858 Mar 7 2015 install.log.syslog
4 drwxr-xr-x 2 root root 4096 Jan 30 2014 ioncube/
4 dr-xr-xr-x 8 root root 4096 May 25 08:08 lib/
12 dr-xr-xr-x 9 root root 12288 May 25 08:09 lib64/
16 drwx------ 2 root root 16384 Mar 7 2015 lost+found/
4 drwxr-xr-x 2 root root 4096 Jul 20 2011 media/
4 drwxr-xr-x 2 root root 4096 Aug 10 04:42 mnt/
4 drwxr-xr-x 18 root root 4096 Aug 13 21:33 opt/
4 -rw-r--r-- 1 root root 220 Dec 9 2015 .pearrc
36 -rw-r--r-- 1 root root 36814 Mar 16 2015 php.ini.new
36 -rw-r--r-- 1 root root 36814 Mar 16 2015 php.ini.orig
0 dr-xr-xr-x 382 root root 0 Jul 7 04:12 proc/
4 drwxr-xr-x 2 root root 4096 Mar 7 2015 public_ftp/
4 drwxr-xr-x 3 root root 4096 Mar 7 2015 public_html/
16 -rw------- 1 root root 15360 Aug 19 08:08 quota.user

You can see in output the file recorded all the contents.

6) How to record terminal activity to different file name ?

If you want to store the output to different file name use the (-a) option to do it. See the output below.

root@cpanel [~]# script -a testsession.txt
Script started, file is testsession.txt

6i) Some activity on terminal ?

I’m going to do some activity on current terminal to check whether its stored or not.

cd /home/islamija/
root@cpanel [/home/islamija]# ls -lsa
total 88
4 drwx--x--x 15 islamija islamija 4096 Aug 19 02:56 ./
4 drwx--x--x 103 root root 4096 Aug 19 07:54 ../
0 lrwxrwxrwx 1 islamija islamija 34 Aug 18 23:08 access-logs -> /usr/local/apache/domlogs/islamija/
4 -rw-r--r-- 1 islamija islamija 18 Mar 31 01:29 .bash_logout
4 -rw-r--r-- 1 islamija islamija 176 Mar 31 01:29 .bash_profile
4 -rw-r--r-- 1 islamija islamija 124 Mar 31 01:29 .bashrc
4 drwxrwx--x 5 islamija islamija 4096 Aug 19 03:38 .cagefs/
4 drwxr-xr-x 2 islamija islamija 4096 Aug 18 22:53 .cl.selector/
4 -rw------- 1 islamija islamija 23 Aug 18 22:53 .contactemail
4 drwx------ 4 islamija islamija 4096 Aug 19 06:37 .cpanel/
4 drwx------ 4 islamija islamija 4096 Aug 18 22:53 .cphorde/
4 drwxr-x--- 3 islamija mail 4096 Aug 19 06:06 etc/
4 -rw-r--r-- 1 islamija islamija 140 Aug 18 22:53 .gemrc
4 drwxr-x--- 2 islamija nobody 4096 Aug 18 22:53 .htpasswds/
4 -rw------- 1 islamija islamija 422 Aug 19 06:18 .lastlogin
4 drwx------ 2 islamija islamija 4096 Aug 18 23:08 logs/
4 drwxr-x--x 10 islamija islamija 4096 Aug 18 22:53 mail/
4 drwxr-x--- 3 islamija islamija 4096 Aug 18 22:53 public_ftp/
4 drwxr-x--- 6 islamija nobody 4096 Aug 19 06:05 public_html/
4 drwx--x--x 4 islamija islamija 4096 Aug 19 02:15 .softaculous/
4 drwxr-xr-x 3 islamija islamija 4096 Aug 19 03:50 tmp/
4 drwx------ 4 islamija islamija 4096 Aug 19 05:26 .trash/
0 lrwxrwxrwx 1 islamija islamija 11 Aug 18 22:53 www -> public_html/
4 -rw-r--r-- 1 islamija islamija 658 Mar 25 12:11 .zshrc
root@cpanel [/home/islamija]# exit
exit
Script done, file is testsession.txt

6ii) Check the recorded/saved contents ?

Just use any text editor or cat or more command to check the recorded/saved contents on testsession.txt file.

more testsession.txt
Script started on Fri 19 Aug 2016 08:14:46 AM CEST
root@cpanel11-nl [/]# cd /home/islamija/
root@cpanel11-nl [/home/islamija]# ls -lsa
total 88
4 drwx--x--x 15 islamija islamija 4096 Aug 19 02:56 ./
4 drwx--x--x 103 root root 4096 Aug 19 07:54 ../
0 lrwxrwxrwx 1 islamija islamija 34 Aug 18 23:08 access-logs -> /usr/local/apache/domlogs/islamija/
4 -rw-r--r-- 1 islamija islamija 18 Mar 31 01:29 .bash_logout
4 -rw-r--r-- 1 islamija islamija 176 Mar 31 01:29 .bash_profile
4 -rw-r--r-- 1 islamija islamija 124 Mar 31 01:29 .bashrc
4 drwxrwx--x 5 islamija islamija 4096 Aug 19 03:38 .cagefs/
4 drwxr-xr-x 2 islamija islamija 4096 Aug 18 22:53 .cl.selector/
4 -rw------- 1 islamija islamija 23 Aug 18 22:53 .contactemail
4 drwx------ 4 islamija islamija 4096 Aug 19 06:37 .cpanel/
4 drwx------ 4 islamija islamija 4096 Aug 18 22:53 .cphorde/
4 drwxr-x--- 3 islamija mail 4096 Aug 19 06:06 etc/
4 -rw-r--r-- 1 islamija islamija 140 Aug 18 22:53 .gemrc
4 drwxr-x--- 2 islamija nobody 4096 Aug 18 22:53 .htpasswds/
4 -rw------- 1 islamija islamija 422 Aug 19 06:18 .lastlogin
4 drwx------ 2 islamija islamija 4096 Aug 18 23:08 logs/
4 drwxr-x--x 10 islamija islamija 4096 Aug 18 22:53 mail/
4 drwxr-x--- 3 islamija islamija 4096 Aug 18 22:53 public_ftp/
4 drwxr-x--- 6 islamija nobody 4096 Aug 19 06:05 public_html/
4 drwx--x--x 4 islamija islamija 4096 Aug 19 02:15 .softaculous/
4 drwxr-xr-x 3 islamija islamija 4096 Aug 19 03:50 tmp/
4 drwx------ 4 islamija islamija 4096 Aug 19 05:26 .trash/
0 lrwxrwxrwx 1 islamija islamija 11 Aug 18 22:53 www -> public_html/
4 -rw-r--r-- 1 islamija islamija 658 Mar 25 12:11 .zshrc
root@cpanel11-nl [/home/islamija]# exit
exit

Script done on Fri 19 Aug 2016 08:17:41 AM CEST

That’all to do.Please Give your opinion below if you experience any issues or to discuss your ideas and experiences.