I often use SSH to connect to ARM machine which reboots regularly and doesn't have any persistent memory to store sh command history. Is there a way to store such history on my local machine so it could be accessible by ^R and up/down when connected to the remote? Or is there another workaround to such problem besides storing most useful commands in a notepad? :)

  • 1
    What shell do you use on the ARM machine? It probably can be configured to store a history file to the ramfs or whatever non-persistent filesystem the machine is using. Then, replace your remote exit comannd by an alias, which copies that history file to your host before exiting and replace your ssh call by a copying of the saved file back to the machine before actually connecting. – Philippos Feb 7 '18 at 8:18
  • @Philippos pure sh (not bash) wrapped into BusyBox 1.20.2 – Artalus Feb 7 '18 at 12:30

A possible solution is the rlwrap program, dating from 1999, which should be available on your home machine in a package of the same name. It uses the GNU readline library to front-end any command with a re-usable history that is saved by default in a file ~/.command_history, so in your case it should end up in ~/.ssh_history if you do:

rlwrap ssh remote

(If you want to test this to a remote running an application or shell that already has readline built-in, you will need to disable the remote readline. For example with a remote bash do: rlwrap ssh remote bash --noediting to see it working.)

  • This looks like a great solution with a single downside: if I use rlwrap ssh user@ip sh --noediting I do not get the shell "prefix" (~/dir $ _ one), just an empty line. Is there a way to fix this? – Artalus Feb 8 '18 at 14:54
  • I was hoping you wouldn't need this option. I was using it because I don't have a remote that runs a busybox sh so was pretending with a remote bash. The problem seems to be a conflict between the remote using readline and so putting the terminal in raw mode, and rlwrap trying to do the same. What might work is to ask ssh to not provide a pty (use -T), but then you will lose job control on the remote. – meuh Feb 8 '18 at 15:18
  • -T in pure ssh causes the same prompt loss, and in rlwrap ssh it doesn't change anything. Also autompletion doesn't work and ^C and ^Z are sent to host machine. Apparently this tool causes more problems than it solves :( – Artalus Feb 8 '18 at 15:56
  • It seems rlwrap -a ssh remote should allow rlwrap to handle the problem you have, without resorting to --noediting in your shell. – meuh Feb 8 '18 at 17:04
  • Yes, the -a option fixes prompt. The autocompletion seems unfixable without direct specifying of completion file, from what I've googled. It is nice to know that there is atleast formal solution to my problem, even with its downsides. – Artalus Feb 9 '18 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.