Originally posted by kevin comario: Can I execute the history command in a bash script? If so could you tell me how so far I have been unsuccessful to do so.
Yes, why not? It's just like any shell script command. What errors are you getting ?
When I use the history command in a bash file it doesnt list anything. So i tried redirecting it to a temp file, and still nothing. Can an admin turn off such a function? Also I am using red hat if that makes a diffrence.
Hi Kevin, I dont think your problem is due to RedHat, rather it is due to bash's history function. By default, bash only enables history for interactive shells. Running a script does not fall under that category. You can turn history on in the script by using the <code>set -o history</code> command in your script. Your next problem (or security feature) is that the history you get will then be for that particular shell. You will not get a history for commands the user has typed. This is generally a good thing. The following script works on my system: