• Skip to primary navigation
  • Skip to main content
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Saving every command and its output in log in Unix

November 25, 2011 by Sharad Chhetri Leave a Comment

In this post we will learn about saving every linux/unix command and its output in log file. The command called script will be use to save the command output in log.

Run script command to save command output in file/log

script  filename.log

Example:

[root@server1 ~]#
[root@server1 ~]# script my.log
Script started, file is my.log
Welcome
[root@server1 ~]#
[root@server1 ~]# date
Thu Nov 24 23:02:39 MST 2011
[root@server1 ~]#
[root@server1 ~]# cal
   November 2011
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

[root@server1 ~]#
[root@server1 ~]# echo "This is  a test"
This is  a test
[root@server1 ~]#
[root@server1 ~]# exit
exit
Script done, file is my.log
[root@server1 ~]#

Now we will see output in my.log file.

[root@server1 ~]#
[root@server1 ~]#  cat my.log
Script started on Thu Nov 24 23:02:35 2011
Welcome
[root@server1 ~]#
[root@server1 ~]# date
Thu Nov 24 23:02:39 MST 2011
[root@server1 ~]#
[root@server1 ~]# cal
   November 2011
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

[root@server1 ~]#
[root@server1 ~]# echo "This is  a test"
This is  a test
[root@server1 ~]#
[root@server1 ~]# exit
exit

Script done on Thu Nov 24 23:03:05 2011
[root@server1 ~]#

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Secondary Logging : Save All Users History Command Output As Log
  2. See mysql command output vertically
  3. Print grep command output without seperator
  4. Learn tar command and know about its precaution
  5. Set group password,its use and check which group after newgrp command in linux
  6. Linux : clear command and its keyboard shortcut
  7. check_memory unable to read output Nagios nrpe
  8. Redirect sudo output to file
  9. How To Find Absolute Full Path Of Command On Linux / Unix : which command
  10. How to create OpenSSH rpm package and its upgrade

Filed Under: Linux Tagged With: logging

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy