[Solved] Alias in ash - syntax or limitation issue

Hello:

As you may have seen in previous posts, I'm running OpenWRT in a NAS (WD-MBL).

Now, I'm putting together a set of aliases to make maintenance easier via the command line.

These work as expected:

alias shutdown='sync && wait && sudo hdparm -Y /dev/sda && wait && sudo halt'

Shuts down the NAS gracefully.

daemon='sudo /etc/init.d/rsyncd status'

Tells me the rsync daemon's status.

drivechk='sudo dmesg | grep -i ext4-fs | grep -i sda'

Alerts me to filesystem issues caused by a bad shutdown requiring e2fsck.

tempchk='sudo smartctl -d ata -A /dev/sda | grep Temperature | cut -c 5-8,87-89'

Tells me the drive temperature.

But there is one which I have not been able to get to work:

fschk='df -h | grep -vE '^Filesystem|/dev/root|tmpfs'| awk '{ print $5 " " $1}'

The stanza run from the command line works as expected:

~$ df -h | grep -vE '^Filesystem|/dev/root|tmpfs'| awk '{ print $5 " " $1}'
53% /dev/sda1
37% /dev/sda3
~$

If I add this to the /etc/profile.d/custom.sh file, log out and log in again I get this on the terminal:

~$ ssh user@192.168.1.3
--- snip ---
BusyBox v1.33.2 (2022-02-16 20:29:10 UTC) built-in shell (ash)

alias:  }' not found

~$ 

Something seems to be wrong.
If I then run the alias I get this:

~$ fschk
> 

Makes sense as on login the system prints out something that implies that something is wrong with the alias.

If I query the alias list from the command line, I see that the one I added is shown differently in the printout:

~$ alias
--- snip ---
fschk='df -h|grep -vE '"'"'^/dev/root|tmpfs'"'"'|awk '"'"'{print  '
--- snip ---
:~$ 

But not in the /etc/profile.d/custom.sh file where it remains as I typed it:

~$ cat /etc/profile.d/custom.sh
--- snip ---
alias fschk="df -h|grep -vE '^/dev/root|tmpfs'|awk '{print $5 " " $1}'"
--- snip ---
~$ 

It seems that ash has a different/reduced version of alias but I cannot figure this one out.

ie: if it works as expected from the command line, why doesn't it work as an alias?

Any pointers will be greatly appreciated.

Thanks in advance.

Best,

PCL

The following appears to work:
alias fschk="(df -h | grep -vE '^Filesystem|/dev/root|tmpfs'|awk '{print \$5 \" \" \$1}')"

I suppose Busybox's ash is a tad buggy or something, but I had to enclose the whole command-line in parentheses to get it to work.

2 Likes

Hello:

Indeed it does. 8^ )

~$ fschk
53% /dev/sda1
37% /dev/sda3
~$ 

Can't say.
I did not know it existed before using OpenWRT.

Thank you very much for taking the time to see what was up.
Now on to the script.

Best,

PCL

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.