What clever SSH shortcuts do you use?

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

brtravel

Occasional Visitor
My friends consider me tech savvy, but that's a low bar, I am quickly lost on command line instructions so I've previously only used the GUI for my Merlin router. However last year Apple made their Shortcuts app a lot more powerful and useful, and I've been having fun automating some things in my phone and in my life, for instance telling Siri to turn on my router VPN. I should think Android phones have a way to quickly run SSH commands as well.

What SSH functions do you regularly use with your Merlin router?


Here's a few I've picked up recently:
  • reboot
  • service restart_wan
  • nvram get vpn_client1_state
  • service start_vpnclient1
  • service stop_vpnclient1
 

Jack Yaz

Part of the Furniture
My friends consider me tech savvy, but that's a low bar, I am quickly lost on command line instructions so I've previously only used the GUI for my Merlin router. However last year Apple made their Shortcuts app a lot more powerful and useful, and I've been having fun automating some things in my phone and in my life, for instance telling Siri to turn on my router VPN. I should think Android phones have a way to quickly run SSH commands as well.

What SSH functions do you regularly use with your Merlin router?


Here's a few I've picked up recently:
  • reboot
  • service restart_wan
  • nvram get vpn_client1_state
  • service start_vpnclient1
  • service stop_vpnclient1
I wrote scMerlin so I wouldn't need to remember the commands :)
 

Dabombber

Senior Member
I have a few in my configs/profile.add which link to an alias script:
Code:
service() { /jffs/scripts/alias.sh service "[email protected]"; }
enable() { /jffs/scripts/alias.sh enable "[email protected]"; }
disable() { /jffs/scripts/alias.sh disable "[email protected]"; }
start() { /jffs/scripts/alias.sh start "[email protected]"; }
stop() { /jffs/scripts/alias.sh stop "[email protected]"; }
restart() { /jffs/scripts/alias.sh restart "[email protected]"; }
opkg() { /jffs/scripts/alias.sh opkg "[email protected]"; }

service extends to entware services, and also shows useful output if you make a typo instead of just "Done."
enable/disable to change entware services autostarting
start/stop/restart shortcuts for "service start_", etc
opkg to colour the output, and a couple of subcommand shortcuts eg) "opkg ls" for "opkg list-installed"
 

brtravel

Occasional Visitor
anyone know the command to query the internet connection status?

edit: pinging google (ping -c 1 -q google.com)
accomplishes this pretty well, but I wonder if someone knows exactly how to query specifically the "Internet status: " field in the Network Map GUI?
 
Last edited:

dave14305

Part of the Furniture
anyone know the command to query the internet connection status?

edit: pinging google (ping -c 1 -q google.com)
accomplishes this pretty well, but I wonder if someone knows exactly how to query specifically the "Internet status: " field in the Network Map GUI?
Try
Code:
nvram get link_internet
2 is normal.
 

RMerlin

Asuswrt-Merlin dev
If you frequently do script editing on the router, create /jffs/configs/nanorc with the following content:

Code:
set nowrap

syntax "sh" "\.sh$"
header "^#!.*((ba|da|k|pdk)?sh[-0-9_]*|openrc-run|runscript)"
magic "(POSIX|Bourne-Again) shell script.*text"
linter dash -n
comment "#"

icolor brightgreen "^[0-9A-Z_]+\(\)"
color green "\<(break|case|continue|do|done|elif|else|esac|exit|fi|for|function|if|in|read|return|select|shift|then|time|until|while)\>"
color green "\<(declare|eval|exec|export|let|local)\>"
color green "[{}():;|`$<>!=&\\]" "(\]|\[)"
color green "-[Ldefgruwx]\>"
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
color brightblue "\<(awk|cat|cd|ch(grp|mod|own)|cp|echo|env|grep|install|ln|make|mkdir|mv|popd|printf|pushd|rm|rmdir|sed|set|tar|touch|umask|unset)\>"

# Basic variable names (no braces).
color brightred "\$[[email protected]*#?$!]" "\$[[:alpha:]_][[:alnum:]_]*"
# More complicated variable names; handles braces and replacements and arrays.
color brightred "\$\{[#!]?([[email protected]*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"

# Comments.
color cyan "(^|[[:space:]])#.*$"

# Strings.
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"

# Trailing whitespace.
color ,green "[[:space:]]+$"
 

Twiglets

Senior Member
Wot no Vi[m] or Emacs !!!
:eek: ;)

<JK>
 

Yota

Regular Contributor
anyone know the command to query the internet connection status?

edit: pinging google (ping -c 1 -q google.com)
accomplishes this pretty well, but I wonder if someone knows exactly how to query specifically the "Internet status: " field in the Network Map GUI?
;)Be careful, it may break google.
My way may not be as simple as @dave14305, but it is very useful for me.
Code:
rm_ipadr="$(nslookup "$(nvram get dns_probe_host)" 2>/dev/null | grep -A1 'Name' | grep -v 'Name' | awk '{print $3}')"
lc_ipadr1="$(nvram get dns_probe_content | awk '{print $1}')"
lc_ipadr2="$(nvram get dns_probe_content | awk '{print $2}')"
if [ "$rm_ipadr" = "$lc_ipadr1" ] || [ "$rm_ipadr" = "$lc_ipadr2" ]; then
     echo "OK"
fi
 

eltell69

Occasional Visitor
Hi Guys I've followed a link provided by JDB from my previous post.
Been using merlin f/w for yonks now very successfully and have recently got netflix on my tv but unless I do a bypass of the vpn for it it does'nt stream and the bypass leaves me unprotected according to my vpn site when I viit their site. So do any of you guys know of a way to control the vpn from an iphone without messing about with the pc and logging in etc.
I have the asus router app installed to check my lan as I have three routers on it but it does'nt cover the vpn.
The main router with the vpn installed is the asus rt-ax88u, any help would be greatly appreciated. Thanks
 

CaptnDanLKW

Regular Contributor
When I want to take down a device cleanly because I'm going to remove the power, I don't like guessing by the LED sequence... so i
sync;sync;halt
 

maghuro

Very Senior Member
I have a few in my configs/profile.add which link to an alias script:
Code:
service() { /jffs/scripts/alias.sh service "[email protected]"; }
enable() { /jffs/scripts/alias.sh enable "[email protected]"; }
disable() { /jffs/scripts/alias.sh disable "[email protected]"; }
start() { /jffs/scripts/alias.sh start "[email protected]"; }
stop() { /jffs/scripts/alias.sh stop "[email protected]"; }
restart() { /jffs/scripts/alias.sh restart "[email protected]"; }
opkg() { /jffs/scripts/alias.sh opkg "[email protected]"; }

service extends to entware services, and also shows useful output if you make a typo instead of just "Done."
enable/disable to change entware services autostarting
start/stop/restart shortcuts for "service start_", etc
opkg to colour the output, and a couple of subcommand shortcuts eg) "opkg ls" for "opkg list-installed"
I've been looking on your repo and you've some interesting stuff :) thanks!
Is it possible to install shellcheck on this router and do the checks without going to their website?
 

Dabombber

Senior Member
I've been looking on your repo and you've some interesting stuff :) thanks!
Is it possible to install shellcheck on this router and do the checks without going to their website?

Unfortunately not, shellcheck is written is haskell which... well there's info here. It might be easier to transliterate shellcheck into another language than compile it for routers.
 

Martineau

Part of the Furniture
It might be easier to transliterate shellcheck into another language than compile it for routers.
Or....even easier .....use a Shellcheck aware editor.? ;)

i.e. Windows users should be using WinSCP, and rather than use it's native Linux aware editor, WinSCP can be customised to use any external Linux aware editor.

e.g. I obviously have notepad++ installed, but I also installed Atom editor with Linter aka Shellcheck

In the WinSCP drop down I can select which editor to use on the router scripts:

upload_2020-5-2_15-12-51.png



and shellcheck provides instant 'helpful' hints on my bad coding habits :rolleyes::rolleyes:

e.g. 7 shellcheck Warnings, and the onehighlighted:

'Remove surrounding $() to avoid executing output [SC2091]'

upload_2020-5-2_15-15-9.png
 

dave14305

Part of the Furniture
Or....even easier .....use a Shellcheck aware editor.? ;)

i.e. Windows users should be using WinSCP, and rather than use it's native Linux aware editor, WinSCP can be customised to use any external Linux aware editor.

e.g. I obviously have notepad++ installed, but I also installed Atom editor with Linter aka Shellcheck

In the WinSCP drop down I can select which editor to use on the router scripts:

View attachment 23212


and shellcheck provides instant 'helpful' hints on my bad coding habits :rolleyes::rolleyes:

e.g. 7 shellcheck Warnings, and the onehighlighted:

'Remove surrounding $() to avoid executing output [SC2091]'

View attachment 23213
I couldn’t figure out what I was missing to get linter to work in Atom when starting from nothing.
Edit: IIRC, it wanted a pointer to an exe which I didn’t have.
 
Last edited:

Dabombber

Senior Member
Obviously there's lots of alternatives for desktop OS's, notepad++ plugins to full IDEs. Having shellcheck on the router itself could help stop silly mistakes while making quick and dirty edits though ssh.


How does
Code:
$(Smart_LineInsert "$FN" "$(echo -e "sh /jffs/addons/unbound/unbound.postconf \"\$1\"\t\t# unbound_manager")" )
differ from
Code:
Smart_LineInsert "$FN" "$(echo -e "sh /jffs/addons/unbound/unbound.postconf \"\$1\"\t\t# unbound_manager")"
 

maghuro

Very Senior Member
Unfortunately not, shellcheck is written is haskell which... well there's info here. It might be easier to transliterate shellcheck into another language than compile it for routers.
Sad enough.
Most of my own scripts have been written via an Android ssh client (using then nano), while I'm procrastinating on the couch, having an insomnia, of even while I'm pooping :p:p:p

Yesterday, with a insomnia, I wrote a script that toggles VPN client on/off, connects to a random AirVPN server (or manually sets one, and verify if it's valid), and gets VPN client status. Relatively simple, but written via my smartphone :p

Later today night, I'll go to my PC and run in through shellcheck to see if everythings ok. As for now, it's working as intended and that's what matter.
 

Martineau

Part of the Furniture
I couldn’t figure out what I was missing to get linter to work in Atom when starting from nothing.
Edit: IIRC, it wanted a pointer to an exe which I didn’t have.
Did you download the shellcheck-xxxxxxx .exe?
 

dave14305

Part of the Furniture
Did you download the shellcheck-xxxxxxx .exe?
No, I remember thinking I still needed to find a linter.exe somewhere. I will give it another go this weekend and see where I trip up.
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top