Command line history (ash_history)

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13880
Location: Netherlands

PostPosted: Mon Dec 30, 2024 9:56    Post subject: Command line history (ash_history) Reply with quote
Starting with build 58953 busybox will keep the last 30 commands used which can be called between sessions with up and down arrows etc.

The commands are saved in /tmp/.ash_history

Code:
root@EA6900:~# cat /tmp/.ash_history
ls -l /tmp
ls -la /tmp
cat /tmp/.ash_history


Although it saves the history between command line session it is not a permanent file, but you can prefill it after a reboot by adding the commands you want in Administration > Commands > Startup e.g.:
Code:
echo "cat /var/log/messages" >> /tmp/.ash_history


or if you have permanent storage, copy a file with your commands to /tmp/.ash_history

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Sponsor
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2152
Location: WV, USA

PostPosted: Tue Dec 31, 2024 4:25    Post subject: Reply with quote
This is a great and long overdue addition. I have been using bash under Entware for many years giving me this ability, but not limited to only 30 lines. My bash history currently is over 500 lines. I just have to run bash first every time I ssh into it. Now I will be able to add bash to the ash history making it 3 whole keystrokes easier. Wink

Type bash then enter (5 keystrokes) or now hit the up arrow (enter) (2 keystrokes). This will save me about 5ms of typing. (I'm joking of course).

Great addition. I will play with it once the next alpha is built.

Thanks @egc and @BS.

_________________
- Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13880
Location: Netherlands

PostPosted: Tue Dec 31, 2024 7:06    Post subject: Reply with quote
You are welcome, I have had this added to my own build for some time and I could persuade BS to add it so that it is now available for all.

Just curious why are you using bash instead of ash as ash is the prevalent shell for almost all third party firmwares including OpenWRT?

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Nuor
DD-WRT User


Joined: 20 Apr 2015
Posts: 176

PostPosted: Tue Dec 31, 2024 16:22    Post subject: Reply with quote
lexridge wrote:
This is a great and long overdue addition.

I completely agree. Thank you very much. BTW Is there a way simple way to increase the history size?
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13880
Location: Netherlands

PostPosted: Tue Dec 31, 2024 16:59    Post subject: Reply with quote
Nuor wrote:
lexridge wrote:
This is a great and long overdue addition.

I completely agree. Thank you very much. BTW Is there a way simple way to increase the history size?


Unfortunately not, it takes up some memory so is a compromise, I have been discussing it and it is possible to work with different configs for busybox per router type so that routers with lots of RAM can have more but we needed to adapt several dozens of configs so it is an administrative burden and thus not feasible at the moment.

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2152
Location: WV, USA

PostPosted: Tue Dec 31, 2024 18:29    Post subject: Reply with quote
egc wrote:
Just curious why are you using bash instead of ash as ash is the prevalent shell for almost all third party firmwares including OpenWRT?

No good reason, other than having been a Linux desktop user since the 90s, it's simply what I am used to.

_________________
- Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
Nuor
DD-WRT User


Joined: 20 Apr 2015
Posts: 176

PostPosted: Sun Jan 05, 2025 20:59    Post subject: Not seeing .ash_history in r58976 Reply with quote
I just installed r58976 on my R9000 and I'm not seeing /tmp/.ash_history in r58976.
History is apparently not being saved between command line restarts. Was this not added to R9000?



Screenshot 2025-01-05 125432.png
 Description:
 Filesize:  64.68 KB
 Viewed:  3367 Time(s)

Screenshot 2025-01-05 125432.png


lazardo
DD-WRT User


Joined: 17 Apr 2014
Posts: 146
Location: SF Bay Area

PostPosted: Wed Mar 05, 2025 21:39    Post subject: Reply with quote
This works on older builds, probably 58953+ also.

shutdown
Code:
nvram set ash_history="$( history | sed 's/^[[:space:]].[0-9]* //' | gzip | uuencode - )"; nvram commit

root@dd-wrt:/tmp# nvram get ash_history
begin 644 -
M'XL(`````````XV-S0K",!"$[S[%4#SH(=K6?\1GD9"T:2`_M4D%I0]O5R(H
M7GJ:W9W]9@#D:'2(OGO,`!20-6D)$T@W$!+K:%M:MNFX&Q7,1)KWB%P;L!K2
M!<O#;26\>T<<_ASC%1G'[\(3W+WC%J&*X*&Y)NN2S1>?-RRS<_H2WEI-O44^
C@1N@GKH=<0**!*A?@*QR>M:`OJ^<\+("H^`7Y,3?HT`!````
`
end

boot
Code:
nvram get ash_history | uudecode - | gunzip > /tmp/.ash_history

root@dd-wrt:/tmp# cat /tmp/.ash_history
history
df
ls
cd /tmp
nvram set ash_history="$( history )"; nvram commit
nvram set ash_history="$( history | gzip )"
nvram get ash_history
nvram set ash_history="$( history | gzip | uuencode - )"
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 416

PostPosted: Wed Apr 23, 2025 22:33    Post subject: Reply with quote
Noticed and appreciate the 30 command history. Thanks @egc!
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum