How do I log all input and output in a terminal session?
How do I keep logs of all the work done via terminal? For example, I want a record of all the work done on database via terminal.
command-line log tty
add a comment |
How do I keep logs of all the work done via terminal? For example, I want a record of all the work done on database via terminal.
command-line log tty
This is also built into sudo.
– Wilhelm Erasmus
Jul 8 '15 at 19:53
I have added my answer you can review
– Mansur Ali
Dec 8 '16 at 7:23
add a comment |
How do I keep logs of all the work done via terminal? For example, I want a record of all the work done on database via terminal.
command-line log tty
How do I keep logs of all the work done via terminal? For example, I want a record of all the work done on database via terminal.
command-line log tty
command-line log tty
edited Jul 10 '12 at 12:31
Eliah Kagan
82.7k22227369
82.7k22227369
asked Jul 10 '12 at 10:58
AnkitAnkit
2,395134474
2,395134474
This is also built into sudo.
– Wilhelm Erasmus
Jul 8 '15 at 19:53
I have added my answer you can review
– Mansur Ali
Dec 8 '16 at 7:23
add a comment |
This is also built into sudo.
– Wilhelm Erasmus
Jul 8 '15 at 19:53
I have added my answer you can review
– Mansur Ali
Dec 8 '16 at 7:23
This is also built into sudo.
– Wilhelm Erasmus
Jul 8 '15 at 19:53
This is also built into sudo.
– Wilhelm Erasmus
Jul 8 '15 at 19:53
I have added my answer you can review
– Mansur Ali
Dec 8 '16 at 7:23
I have added my answer you can review
– Mansur Ali
Dec 8 '16 at 7:23
add a comment |
3 Answers
3
active
oldest
votes
When you are ready to start recording a log file, type:
script screen.log
Now, until you stop the script, all input and output in the Terminal will be stored in screen.log. When you are done, just type:
exit
Your screen.log file will stored in the local directory. If you want to redirect it, use an absolute pathname such as ~/screen.log
. This will do exactly what you are looking for.
Source: Ubuntu Guide - How To Log Terminal Commands
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
2
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (man script
) even mentionsvi
(editor)...
– Izzy
Jul 10 '12 at 14:21
add a comment |
You may want to try out Asciinema. In addition to just making a recording you get the ability to share it and embed the player on your blog, article or in a conference talk.
add a comment |
I have a better way to use syslog for logging every shell command this can be vary upon linux distribution but method will remain same
You need to follow some steps:
Step # 1 (Create Syslog service)
# vim /etc/rsyslog.d/bash.conf
local6.* /var/log/commands.log
Step # 2 (Open bashrc and enter below command)
# vim /root/.bashrc
# Enable CLI Logging by Mansur 08-12-2016
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]+[ ]*//" ) [$RETRN_VAL]"'
Ste # 3 (Restart Syslog Service)
# /etc/init.d/rsyslog
Here is a log sample:
Dec 7 22:13:00 validationdb2 mahasan: root@export [13291]: tail -f /var/log/mysql/mysql.log [0]
Dec 7 22:13:09 validationdb2 mahasan: root@export [13291]: ls -lh [0]
Dec 7 22:13:27 validationdb2 mahasan: root@export [13291]: touch test command [0]
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f161935%2fhow-do-i-log-all-input-and-output-in-a-terminal-session%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you are ready to start recording a log file, type:
script screen.log
Now, until you stop the script, all input and output in the Terminal will be stored in screen.log. When you are done, just type:
exit
Your screen.log file will stored in the local directory. If you want to redirect it, use an absolute pathname such as ~/screen.log
. This will do exactly what you are looking for.
Source: Ubuntu Guide - How To Log Terminal Commands
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
2
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (man script
) even mentionsvi
(editor)...
– Izzy
Jul 10 '12 at 14:21
add a comment |
When you are ready to start recording a log file, type:
script screen.log
Now, until you stop the script, all input and output in the Terminal will be stored in screen.log. When you are done, just type:
exit
Your screen.log file will stored in the local directory. If you want to redirect it, use an absolute pathname such as ~/screen.log
. This will do exactly what you are looking for.
Source: Ubuntu Guide - How To Log Terminal Commands
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
2
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (man script
) even mentionsvi
(editor)...
– Izzy
Jul 10 '12 at 14:21
add a comment |
When you are ready to start recording a log file, type:
script screen.log
Now, until you stop the script, all input and output in the Terminal will be stored in screen.log. When you are done, just type:
exit
Your screen.log file will stored in the local directory. If you want to redirect it, use an absolute pathname such as ~/screen.log
. This will do exactly what you are looking for.
Source: Ubuntu Guide - How To Log Terminal Commands
When you are ready to start recording a log file, type:
script screen.log
Now, until you stop the script, all input and output in the Terminal will be stored in screen.log. When you are done, just type:
exit
Your screen.log file will stored in the local directory. If you want to redirect it, use an absolute pathname such as ~/screen.log
. This will do exactly what you are looking for.
Source: Ubuntu Guide - How To Log Terminal Commands
edited Nov 1 '16 at 23:34
Alan Thompson
1616
1616
answered Jul 10 '12 at 11:21
xlukasxxlukasx
99178
99178
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
2
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (man script
) even mentionsvi
(editor)...
– Izzy
Jul 10 '12 at 14:21
add a comment |
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
2
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (man script
) even mentionsvi
(editor)...
– Izzy
Jul 10 '12 at 14:21
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
Hi, thanks for the reply. But will this work if I login to the mysql database from the shell using the following sequence:- 1) script screen.log 2)mysql -u <user> -p <database> 3) some work on the database 4) exit; I see that the file screen.log is created but it doesn't contain logs for the database. I'll share the file asap. Thanks Ankt
– Ankit
Jul 10 '12 at 14:15
2
2
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (
man script
) even mentions vi
(editor)...– Izzy
Jul 10 '12 at 14:21
it should work with everything running in the console reading from "standard input" (usually your keyboard) and writing to standard output (usually your terminal window). So it should include the mysql command-line client. The man page (
man script
) even mentions vi
(editor)...– Izzy
Jul 10 '12 at 14:21
add a comment |
You may want to try out Asciinema. In addition to just making a recording you get the ability to share it and embed the player on your blog, article or in a conference talk.
add a comment |
You may want to try out Asciinema. In addition to just making a recording you get the ability to share it and embed the player on your blog, article or in a conference talk.
add a comment |
You may want to try out Asciinema. In addition to just making a recording you get the ability to share it and embed the player on your blog, article or in a conference talk.
You may want to try out Asciinema. In addition to just making a recording you get the ability to share it and embed the player on your blog, article or in a conference talk.
answered Nov 15 '13 at 16:04
sickillsickill
35933
35933
add a comment |
add a comment |
I have a better way to use syslog for logging every shell command this can be vary upon linux distribution but method will remain same
You need to follow some steps:
Step # 1 (Create Syslog service)
# vim /etc/rsyslog.d/bash.conf
local6.* /var/log/commands.log
Step # 2 (Open bashrc and enter below command)
# vim /root/.bashrc
# Enable CLI Logging by Mansur 08-12-2016
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]+[ ]*//" ) [$RETRN_VAL]"'
Ste # 3 (Restart Syslog Service)
# /etc/init.d/rsyslog
Here is a log sample:
Dec 7 22:13:00 validationdb2 mahasan: root@export [13291]: tail -f /var/log/mysql/mysql.log [0]
Dec 7 22:13:09 validationdb2 mahasan: root@export [13291]: ls -lh [0]
Dec 7 22:13:27 validationdb2 mahasan: root@export [13291]: touch test command [0]
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
add a comment |
I have a better way to use syslog for logging every shell command this can be vary upon linux distribution but method will remain same
You need to follow some steps:
Step # 1 (Create Syslog service)
# vim /etc/rsyslog.d/bash.conf
local6.* /var/log/commands.log
Step # 2 (Open bashrc and enter below command)
# vim /root/.bashrc
# Enable CLI Logging by Mansur 08-12-2016
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]+[ ]*//" ) [$RETRN_VAL]"'
Ste # 3 (Restart Syslog Service)
# /etc/init.d/rsyslog
Here is a log sample:
Dec 7 22:13:00 validationdb2 mahasan: root@export [13291]: tail -f /var/log/mysql/mysql.log [0]
Dec 7 22:13:09 validationdb2 mahasan: root@export [13291]: ls -lh [0]
Dec 7 22:13:27 validationdb2 mahasan: root@export [13291]: touch test command [0]
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
add a comment |
I have a better way to use syslog for logging every shell command this can be vary upon linux distribution but method will remain same
You need to follow some steps:
Step # 1 (Create Syslog service)
# vim /etc/rsyslog.d/bash.conf
local6.* /var/log/commands.log
Step # 2 (Open bashrc and enter below command)
# vim /root/.bashrc
# Enable CLI Logging by Mansur 08-12-2016
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]+[ ]*//" ) [$RETRN_VAL]"'
Ste # 3 (Restart Syslog Service)
# /etc/init.d/rsyslog
Here is a log sample:
Dec 7 22:13:00 validationdb2 mahasan: root@export [13291]: tail -f /var/log/mysql/mysql.log [0]
Dec 7 22:13:09 validationdb2 mahasan: root@export [13291]: ls -lh [0]
Dec 7 22:13:27 validationdb2 mahasan: root@export [13291]: touch test command [0]
I have a better way to use syslog for logging every shell command this can be vary upon linux distribution but method will remain same
You need to follow some steps:
Step # 1 (Create Syslog service)
# vim /etc/rsyslog.d/bash.conf
local6.* /var/log/commands.log
Step # 2 (Open bashrc and enter below command)
# vim /root/.bashrc
# Enable CLI Logging by Mansur 08-12-2016
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]+[ ]*//" ) [$RETRN_VAL]"'
Ste # 3 (Restart Syslog Service)
# /etc/init.d/rsyslog
Here is a log sample:
Dec 7 22:13:00 validationdb2 mahasan: root@export [13291]: tail -f /var/log/mysql/mysql.log [0]
Dec 7 22:13:09 validationdb2 mahasan: root@export [13291]: ls -lh [0]
Dec 7 22:13:27 validationdb2 mahasan: root@export [13291]: touch test command [0]
edited Jan 12 '17 at 23:39
wjandrea
9,30842664
9,30842664
answered Dec 8 '16 at 7:17
Mansur AliMansur Ali
24133
24133
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
add a comment |
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
cheeky tactic!!!
– Tom H
Mar 7 '17 at 19:19
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
Hi Mansur, Could you please explain what you are doing with those commands, its difficult to understand, atleast to me.
– Jasser
Oct 16 '17 at 11:03
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
In Step 1 i am naming a service for command logging that will be used by process to send logs to it "local6" would be the end point for service for logging In Step 2 i am setting things what actually i want "PROMPT_COMMAND='RETRN_VAL=$?" this portion will record user's input and "logger -p local6.debug" this will send the log file to service which record logs data with the help syslog process
– Mansur Ali
Oct 16 '17 at 12:08
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f161935%2fhow-do-i-log-all-input-and-output-in-a-terminal-session%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This is also built into sudo.
– Wilhelm Erasmus
Jul 8 '15 at 19:53
I have added my answer you can review
– Mansur Ali
Dec 8 '16 at 7:23