What's new

bash history

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Chrysalis

Senior Member
The shell I want to remember my command history between sessions, anyone worked out a viable way of doing this?

As well as preserving logs especially between reboots.
 
Would very much like this!
 
OK, this works for me. Not sure this is the best way to do it. Correct me if I'm wrong.

With Entware installed do:
Code:
opkg update && opkg upgrade
opkg install bash
Edit /tmp/mnt/sda1/entware/etc/profile
Note that my histfile is in /tmp/mnt/sda1/history/.bash_history
Edit if necessary.
Code:
# Please note it's not a system-wide settings, it's only for a current
# terminal session. Point your f\w (if necessery) to execute /opt/etc/profile
# at console logon.

export PATH='/opt/usr/sbin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin'
export TERM=xterm
export TMP=/opt/tmp
export TEMP=/opt/tmp
export HISTFILE=/tmp/mnt/sda1/history/.bash_history
export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
export HISTSIZE=1000                   # big big history
export HISTFILESIZE=1000              # big big history
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

# You may define localization
#export LANG='ru_RU.UTF-8'
#export LC_ALL='ru_RU.UTF-8'
export TERMINFO=/opt/share/terminfo
Just check that your /tmp/etc/profile has these entries. If the are present all is OK.
Code:
[ -f /opt/etc/profile ] && . /opt/etc/profile
[ -f /jffs/configs/profile.add ] && . /jffs/configs/profile.add
Now we do the big trick by telling which shell to use when booting (from busybox to bash):
Create or add to /jffs/configs/profile.add
Code:
[ -f /opt/bin/bash ] && exec /opt/bin/bash
Reboot and happy bash history!

Edit: Removed Entware package bash-completion. No longer available.
 
Last edited:
Is this still valid?
How do we save the command history and use it on other terminal?
 
Is this still valid?
How do we save the command history and use it on other terminal?

Diversion does keep a shell history by default.
 
To keep it across reboots without installing bash (using the built in ash)....make a /jffs/tmp directory if you don't already have one

add to /jffs/scripts/services-stop
Code:
# Save ash history
cp -f /tmp/home/root/.ash_history /jffs/tmp/.ash_history

add to /jffs/scripts/init-start
Code:
# Restore ash history
cp -f /jffs/tmp/.ash_history /tmp/home/root/.ash_history
 
Similar threads
Thread starter Title Forum Replies Date
sesardelaisla Solved bash executable script problems when executed through a cron job Asuswrt-Merlin 20

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top