Make command line history persistent

By default, the command line history is stored as long as you don't reboot/power off the router. However, You can make it persistent by using permanent storage, such as JFFS or USB attached storage.

The command history is kept in: “/tmp/home/root/.ash_history”.

FreshTomato can execute a script at boot and at shutdown to backup and restore the command history to make it persistent across reboots. To achieve this, we need 2 scripts. One script will execute at shutdown to backup the history to permanent storage. The other will restore the history on boot.



This shutdown script will save the last 100 commands used.
To save more, change '100' to whatever number you wish.
Name your backup script “cli_history_save.autostop” and use
the following code:

cli_history_save.autostop
#!/bin/sh
 
tail -n 100 /tmp/home/root/.ash_history > ${1}/.ash_history



The second script will restore the command history when booting.
Name your restore script “cli_history_restore.autorun”:

cli_history_restore.autorun
#!/bin/sh
 
cp -f ${1}/.ash_history /tmp/home/root/.ash_history



You must place the scripts in the mounted storage directory,
(such as “/jffs” for JFFS or “/tmp/mnt/sda1” for USB).
Replace “sda1” with your actual partition name. Then, make the scripts
executable with chmod:

chmod +x cli_history_save.autostop cli_history_restore.autorun