Site Tools


ash_history

This is an old revision of the document!


Make command line history Persistent

By default, the command line history is stored as long as you don't reboot or power off your router. However, It's possible to 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

We can use FreshTomato's ability to execute a script at boot and at shutdown to backup and restore the command history to make it persistent across reboots. To do so, we need 2 scripts. One script will execute on shutdown to backup the history to permanent storage. The other will restore the history on boot.



This shutdown script will save the last 100 used commands. If you want to keep more, change '100' to the 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



This 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



Make sure to place the scripts in the storage mount directory, for example: /jffs for JFFS or /tmp/mnt/sda1 for USB. (Replace 'sda1' with the name of the partition). Then, make the scripts executable with chmod.

chmod +x cli_history_save.autostop cli_history_restore.autorun



ash_history.1727189914.txt.gz · Last modified: 2024/09/24 15:58 by hogwild