Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Script to save data from bash_history?
Script to save data from bash_history?
I want to keep in a file history of all 'apt-get install' commands i am running. Is it possible with a bash script, that will be set to run every 24 hours, to check .bash_history file for new lines that contain 'apt-get install' and copy the lines in a text file?
Re: Script to save data from bash_history?
That's completely possible. What have you come up with so far?
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
Re: Script to save data from bash_history?
You're over-thinking the problem. It would be better to add the "apt-get" command to a file each time it's invoked. That would save doing a search and running any cron jobs.
I have something that will do what you want.
I have something that will do what you want.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
Re: Script to save data from bash_history?
What if you or the user accidentally installs with
or
Do you want to save those too?
Code: Select all
apt install
Code: Select all
aptitude install
-
- Posts: 1100
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: Script to save data from bash_history?
These command are already logged in /var/log/apt/history.log, it give you user name, date/time started and stopped and all packages (dependencies) installed.
Re: Script to save data from bash_history?
Only the successful installations are recorded. Aborted calls are not, for example. You might want those too.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
Re: Script to save data from bash_history?
I didn't know about history.log. Will be useful.
I was thinking about script like this:
But it will generate duplicate lines which i have to clean after that which is not a big problem if there is no another way. Also i don't know how to setup the script to run every 24 hours.
I was thinking about script like this:
Code: Select all
grep -a 'apt-get install' .bash_history >> history.txt
Re: Script to save data from bash_history?
this.Dai_trying wrote:These command are already logged in /var/log/apt/history.log, it give you user name, date/time started and stopped and all packages (dependencies) installed.
i wish there was a +1 button here somewhere.
Re: Script to save data from bash_history?
Does the OP only want the "apt-get install" commands? The contents of /var/log/apt/history.log shows more than that. So it would still mean a script to parse that.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
-
- Posts: 1100
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: Script to save data from bash_history?
One line could easily do that...
grep Commandline /var/log/apt/history.log
grep Commandline /var/log/apt/history.log
Re: Script to save data from bash_history?
^ fishing for compliments now?
but yes, it's a no-brainer.
except you need a second oneliner:
but yes, it's a no-brainer.
except you need a second oneliner:
Code: Select all
zcat history*gz|grep Commandline
-
- Posts: 1100
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: Script to save data from bash_history?
Noooo, but I do accept them when givendebiman wrote:^ fishing for compliments now?
Useful if your logs are rolled (mine aren't by default)debiman wrote:but yes, it's a no-brainer.
except you need a second oneliner:Code: Select all
zcat history*gz|grep Commandline
- dermitdemdino
- Posts: 3
- Joined: 2017-04-17 06:33
- Location: Hückeswagen