History command inside bash manuscript

History is a covering - constructed in command I could not able to make use of that within a BASH manuscript. So, Is there a means acquire this making use of BASH manuscript?
Below we go my manuscript for you:

#!/bin/bash
history |  tail -100 > /tmp/history.log
cd /tmp
uuencode history.log history.txt  | mail -s "History log of server" [email protected]
0
2019-05-13 03:11:05
Source Share
Answers: 3

I'm not exactly sure if it in fact makes use of the background capacity when running non - interactively, or else every covering manuscript you run would certainly mess up your command history.

Why not go straight to the resource ${HOME}/.bash_history, change history | tail -100 with tail -100 ${HOME}/.bash_history. (If you make use of timestamps you 'd possibly need to do something along the lines of grep -v ^# ${HOME}/.bash_history | tail -100).

0
2019-05-17 15:49:43
Source

The background builtin appears to be impaired inside a shell manuscript. See below: http://www.tldp.org/LDP/abs/html/histcommands.html

I have actually not located any kind of main documents concerning this.

0
2019-05-17 15:35:59
Source

Bash disables background in noninteractive coverings by default, yet you can transform it on.

#!/bin/bash
HISTFILE=~/.bash_history
set -o history
history | tail …

But if you are attempting to check task on that particular web server, the covering background is pointless (it is unimportant to run commands that do not turn up in the background). See How can I log all process launches in Linux.

If you are debugging a manuscript after that shell background is not the most effective means to get valuable details. A better device is the debug trace center : placed set -x near the top of the manuscript. The trace is contacted typical mistake.

0
2019-05-17 07:52:45
Source