Enable shell history

No need to patch. It's a bit of an overkill to save the flash.

I have put just this 3 lines into rc.local:

if [ -f /root/.ash_history ]; then rm /root/.ash_history; fi
touch /tmp/.ash_history
ln -s /tmp/.ash_history /root/.ash_history

Personally I've added to the mentioned settings:

CONFIG_BUSYBOX_CONFIG_FEATURE_REVERSE_SEARCH=y

to dash through the history.

3 Likes

thanks dude seems the logical and simplest way to achieve some back key history

Is this still valid on current main branch? I get no such file.

root@QNAP:~# cat /etc/profile.d/busybox-history-file.sh
cat: can't open '/etc/profile.d/busybox-history-file.sh': No such file or directory

I have /root/.ash_history though.
And I use the eMMC drive on my QNAP mounted as /mnt/extra to save some data that survives sysyupgrades and want to put history file there.
Probably I can use this solution

Well, naturally you need to create that file, and set there the needed variable

1 Like

I've put this in my rc.local

if [ -f /root/.ash_history ]; then rm /root/.ash_history; fi
touch /mnt/extra/.ash_history
ln -s /mnt/extra/.ash_history /root/.ash_history

But when the history is saved the file that is changed is still /root/.ash_history not /mnt/extra/.ash_history as I expect. The main purpose is when I reboot or I do sysupgrade my shell history to be preserved.

re: /mnt, when is it extent.

1 Like

I don't get it?

Presumably you are mounting something with fstab?, and this bit is in rc.local. I do not know the order of things being executed on a boot. But if rc.local happens before fstab, you would be putting things in place on /mnt and then mounting over /mnt. umount and check?

On this actual mod, seems like that rm would be better implemented as a mv...

1 Like

I've tried to run this first in terminal not from rc.local.
Then the /root/.ash_history is deleted,
/mnt/extra/.ash_history is created
/root/.ash_history symlink is creatred
I run some commands in terminal and exit.
I expect the history to be saved in /mnt/extra/.ash_history but it is saved in /root/.ash_history that is now a file not a simlink and the /mnt/extra/.ash_history isn't changed at all.

Yep, just tested to that result. IDK, the idea, at least for BB as I have it built, fails.

1 Like

I don't know why linking it to /mnt/extra does not work. I can only guess here. Its either a filesystem issue (is /mnt/extra ntfs/fat or sth. else?) or its a timing issue regarding mounting things.
Linking it to /tmp is working here. But I don't care across reboots.

EDIT: Now I see the problem. As soon I'm exiting the shell the link is deleted. oO

EDIT2: Both files exist as sperate files after exiting the shell. Commands are collected within /root/.ash_history only after. I don't know what is going on here. From a logical standpoint it should work. Looks like a busybox issue.

EDIT3: O.K. I didn't observe this behaviour in the past.

I fixed it by moving this into .profile:

cat <<'EOF' > /root/.profile
export HISTFILE='/tmp/.ash_history'
EOF

This works for /tmp across reboots. I didn't test for other mounts. But it should work also as long the mount is available upon login.

Actually easier then the previous hack which is not needed anymore.

1 Like

Actually I'm mostly experimenting with usage of the extra eMMC partition but for shell history I won't bother to make any changes if /root/.ash_history survives reboots and sysupgrades.
I think it will survive sysupgrades as I added it to the Flash Operation configuration.
image
Generating backup archive saves the /root/.ash_history in the archive. I've chosen to save history only on exit.
That works and I don't need to touch anything else.

1 Like

Please note: /root/.ash_history doesn't work anymore on latest SNAPSHOT.

I was scratching my head my histories was not loading after a sysupgrade and reboots. Only to find out the history file has been moved to: /tmp/.busybox_ash_history

See my post here for more info: Shell History name and location changes?

The change is actually a environment variable, see: /etc/profile.d/busybox-history-file.sh

NOTE: The changes was to prevent flash memory wear.

3 Likes