Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

1 votes
2 answers
3506 views
Automatically entering ssh password from Busybox terminal
I currently am attempting to reboot a modem via ssh using a bash script. For reasons I don't feel like explaining, I NEED to start on an ubuntu server computer, ssh into a setup running busybox 1.21.1 and then ssh into the modem from there and reboot it. I need the busybox system to automatically in...
I currently am attempting to reboot a modem via ssh using a bash script. For reasons I don't feel like explaining, I NEED to start on an ubuntu server computer, ssh into a setup running busybox 1.21.1 and then ssh into the modem from there and reboot it. I need the busybox system to automatically input the password when sshing into the modem. To do this when sshing into the busybox system from the ubuntu server, I use sshpass in the following: sshpass -p password ssh busybox@xx.xx.xx.xx 'ssh modem@xx.xx.xx.xx' and running this gets me to the password prompt for the modem. My problem is that the busybox system only has a small amount of commands available for use and none of them are sshpass or expect, which are the only two commands I know to use to automatically interact with the ssh password prompt. The defined functions on the busybox installation are [, [[, addgroup, adduser, ar, arping, ash, awk, basename, blkid, bunzip2, bzcat, cat, catv, chattr, chgrp, chmod, chown, chroot, chrt, chvt, cksum, clear, cmp, cp, cpio, crond, crontab, cut, date, dc, dd, deallocvt, delgroup, deluser, devmem, df, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap, echo, egrep, eject, env, ether-wake, expr, false, fdflush, fdformat, fgrep, find, fold, free, freeramdisk, fsck, fuser, getopt, getty, grep, gunzip, gzip, halt, hdparm, head, hexdump, hostid, hostname, hwclock, id, ifconfig, ifdown, ifup, inetd, init, insmod, install, ip, ipaddr, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kill, killall, killall5, klogd, last, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, losetup, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, makedevs, md5sum, mdev, mesg, microcom, mkdir, mkfifo, mknod, mkswap, mktemp, modprobe, more, mount, mountpoint, mt, mv, nameif, netstat, nice, nohup, nslookup, od, openvt, passwd, patch, pidof, ping, pipe_progress, pivot_root, poweroff, printenv, printf, ps, pwd, rdate, readlink, readprofile, realpath, reboot, renice, reset, resize, rm, rmdir, rmmod, route, run-parts, runlevel, sed, seq, setarch, setconsole, setkeycodes, setlogcons, setserial, setsid, sh, sha1sum, sha256sum, sha3sum, sha512sum, sleep, sort, start-stop-daemon, strings, stty, su, sulogin, swapoff, swapon, switch_root, sync, sysctl, syslogd, tail, tar, tee, telnet, test, tftp, time, top, touch, tr, traceroute, true, tty, udhcpc, umount, uname, uniq, unix2dos, unlzma, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat Does anyone know of anything I can use to automatically input this password when sshing from the the busybox system into the modem? Any help or ideas would be appreciated EDIT: ssh key authentication is a no go due to lack of support from the modem. Edit2: could someone at least comment and let me know if the question I'm asking makes that much sense? Trying hard to get a clear explanation of my problem so someone with the real know how can help me. Let me know if there's any part to my question that is confusing or if there is more detail I can provide.
wvu_evan12 (11 rep)
Sep 27, 2015, 10:57 PM • Last activity: Jul 11, 2025, 03:00 AM
0 votes
1 answers
327 views
How can I correctly configure Docker Rootless to run as a service on Alpine Linux
I need to run Docker Rootless on an Alpine Linux 3.19.0 instance. I have followed the instructions of [this blogpost][1] in order to create a basic setup with an user named ```dev```. I wish to configure it as an rc-service so as to keep the Rootless Docker service constantly running under the hood....
I need to run Docker Rootless on an Alpine Linux 3.19.0 instance. I have followed the instructions of this blogpost in order to create a basic setup with an user named
. I wish to configure it as an rc-service so as to keep the Rootless Docker service constantly running under the hood. However, the script setup on the blog post has an apparent problem with the $PATH variable (I imagine the problem is there, although I do not know Linux that much) in which trying to run this service: #!/sbin/openrc-run name=$RC_SVCNAME description="Docker Application Container Engine (Rootless)" supervisor="supervise-daemon" command="/home/dev/bin/dockerd-rootless.sh" command_args="" command_user="dev" supervise_daemon_args=" -e PATH=\"/home/dev/bin:/sbin:/usr/sbin:$PATH\" -e HOME=\"/home/\" -e XDG_RUNTIME_DIR=\"/home/dev/.docker/run\"" reload() { ebegin "Reloading $RC_SVCNAME" /bin/kill -s HUP \$MAINPID eend $? } while using these variables in
/home/dev/.profile
:
export XDG_RUNTIME_DIR="$HOME/.docker/run"
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
export PATH="/home/dev/bin:/sbin:/usr/sbin:$PATH"
returns this very long error which I do not know the cause of:
/lib/rc/sh/openrc-run.sh: /etc/init.d/docker-rootless: line 9: supervise-daemon-args= -e "/home/dev/bin:/sbin:/usr/sbin:/lib/rc/sbin:/lib/rc/bin:/bin:/sbin:/bin:/sbin:/usr/shbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" -e "/home/dev" =e "home/dev/.docker/run": not found
If anyone could help me to realize where the error is I would be very thankful.
Felipe Mastromauro Corrêa (1 rep)
Jan 14, 2025, 01:47 PM • Last activity: Feb 16, 2025, 08:56 PM
0 votes
1 answers
256 views
How to execute history command by number in Alpine Linux (busybox, ash)?
Is it possible to execute a history command by number with `!###`, similar to bash/zsh? Alpine's ash shell does not interpret this: ```terminal $ history 1441 date 1442 history $ !1141 -sh: !1141: not found ```
Is it possible to execute a history command by number with !###, similar to bash/zsh? Alpine's ash shell does not interpret this:
$ history
1441 date
1442 history

$ !1141
-sh: !1141: not found
anthumchris (161 rep)
Dec 7, 2024, 03:35 PM • Last activity: Dec 10, 2024, 07:13 AM
-1 votes
2 answers
217 views
Where is the prompt configured in ash's login shell?
I can login on an alpine based docker container by either a non-login or non-login shell, i.e. `ash` vs `ash -l`. ``` $ docker run -it --rm alpine /bin/ash / # ``` Now when I use the login shell, I see a weird string in the left on the prompt: ``` $ docker run -it --rm alpine /bin/ash -l 46d4c6007f7...
I can login on an alpine based docker container by either a non-login or non-login shell, i.e. ash vs ash -l.
$ docker run -it --rm alpine /bin/ash
/ #
Now when I use the login shell, I see a weird string in the left on the prompt:
$ docker run -it --rm alpine /bin/ash -l
46d4c6007f75:/#
I wonder where that is coming from, I assumed it was the username but whoami says it is root. I want to modify the appearance of the login shell for my alpine based container for the login shell, yet I have no clue where its defined.
k0pernikus (16501 rep)
Sep 11, 2024, 02:14 AM • Last activity: Sep 11, 2024, 02:24 AM
7 votes
3 answers
15136 views
urlencode function
I need a way to URL encode strings with a shell script on a OpenWRT device running old version of busybox. Right now I ended up with the following code: urlencode() { echo "$@" | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | while read l do c="`echo "$l" | grep '[^-._~0-9a-zA-Z]'`" if [ "$l" == "" ]...
I need a way to URL encode strings with a shell script on a OpenWRT device running old version of busybox. Right now I ended up with the following code: urlencode() { echo "$@" | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | while read l do c="echo "$l" | grep '[^-._~0-9a-zA-Z]'" if [ "$l" == "" ] then echo -n "%20" else if [ -z "$c" ] then echo -n "$l" else printf %%%02X \'"$c" fi fi done echo "" } This works more or less fine but there're a few flaws: 1. Some characters are skipped, like "\", for example. 2. Result is return character by character so it's extremely slow. It takes about 20 seconds to url encode just a few strings inside a batch. My version of bash doesn't support substring like this ${var:x:y}.
Serg (173 rep)
Jan 8, 2013, 05:35 PM • Last activity: Apr 21, 2024, 05:26 PM
0 votes
3 answers
523 views
How to make 'adb shell' to read /etc/profile or other configuration files?
I am working on an embedded Linux system (kernel-5.10.24), and it uses `ash` from `busybox` as `/bin/sh`. The system support login from serial console and `adb shell` from PC. Now I found the `shell` started from serial console did read the environments defined in `/etc/profile`, but the `shell` sta...
I am working on an embedded Linux system (kernel-5.10.24), and it uses ash from busybox as /bin/sh. The system support login from serial console and adb shell from PC. Now I found the shell started from serial console did read the environments defined in /etc/profile, but the shell started by adb shell does NOT. For example, the /etc/profile is as follows,
# cat /etc/profile
export PATH="/bin:/sbin:/usr/bin:/usr/sbin"

if [ "$PS1" ]; then
        if [ "id -u" -eq 0 ]; then
                export PS1='# '
        else
                export PS1='$ '
        fi
fi
in serial console,
# echo $HOME
/root
# echo $ENV

# echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin
But in adb shell,
/sys/kernel/config/usb_gadget # echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin
/sys/kernel/config/usb_gadget # echo $HOME
/
The shell started by adb shell is launched by adbd in target Linux, so is there a way to make the shell started by adb shell to read /etc/profile or other configuration files for its environments?
wangt13 (631 rep)
Aug 25, 2023, 03:11 AM • Last activity: Mar 2, 2024, 11:13 AM
25 votes
5 answers
33445 views
Set environment variable for subshell
I know that I can run a command with an environment variable like this: FOO=bar mycommand I know that I can run commands in a subshell like this: (firstcommand && secondcommand) But can I somehow combine those two? FOO=bar (firstcommand && secondcommand) gives: > sh: syntax error: unexpected "(" at...
I know that I can run a command with an environment variable like this: FOO=bar mycommand I know that I can run commands in a subshell like this: (firstcommand && secondcommand) But can I somehow combine those two? FOO=bar (firstcommand && secondcommand) gives: > sh: syntax error: unexpected "(" at least in busybox shell (ash). **Edit:** Kusalananda suggested FOO=bar sh -c 'first && second' which is indeed a solution. However, I am also interested in alternative answers because I like the subshell syntax because it doesn't require fiddling around with escaping of quotes.
AndreKR (1218 rep)
Sep 13, 2017, 06:03 PM • Last activity: Jun 26, 2023, 03:45 PM
52 votes
3 answers
47481 views
Ash profile/configuration file
I am looking for a way to customize Ash sessions with my own sets of `alias`es and whatnots. What is the Ash equivalent of Bash's `bashrc` files?
I am looking for a way to customize Ash sessions with my own sets of aliases and whatnots. What is the Ash equivalent of Bash's bashrc files?
reg (1203 rep)
Dec 26, 2014, 05:54 PM • Last activity: Apr 21, 2023, 09:51 AM
1 votes
0 answers
1259 views
Merge set x (xtrace) and v (verbose)
How to merge `set -x` and `set -v` in `ash`? (or `set -v` with a prefix) In other words, echo back command upon running. The `DEBUG` signal does not exist in `ash`: `DEBUG: invalid signal specification`. **`set -x`** ```shell $ echo > foo.txt # Normal $ set -x $ echo > foo.txt # Example + echo $ # M...
How to merge set -x and set -v in ash? (or set -v with a prefix) In other words, echo back command upon running. The DEBUG signal does not exist in ash: DEBUG: invalid signal specification. **set -x**
$ echo > foo.txt # Normal
$ set -x
$ echo > foo.txt # Example
+ echo
$ # Missing "> foo.txt # Example"
**set -v**
$ echo > foo.txt # Normal
$ set -v
$ echo > foo.txt # Example
echo > foo.txt # Example
$ # Missing prefix "> "
**set -xv**
$ echo > foo.txt # Normal
$ set -vx
$ echo > foo.txt # Example
echo > foo.txt # Example
+ echo
$ # Now there are two problems... (missing "> foo.txt  # Example" and missing prefix "> ")
**Desired**
$ echo > foo.txt # Normal
$ magic_command "> "
$ echo > foo.txt # Example
> echo > foo.txt # Example
$ ls
> ls
foo.txt
wjwrpoyob (460 rep)
Apr 13, 2023, 03:17 AM • Last activity: Apr 13, 2023, 05:26 AM
2 votes
1 answers
852 views
Stop stdin while command is running
How to stop `stdin` while command is running in `ash` (not `bash`)? For example: 1. `sleep 10` 1. type `echo hello` while `sleep` is still running 1. observe `hello` is in `stdout` after `sleep` finishes Desired: 1. `sleep 10` 1. type `echo hello` while `sleep` is still running 1. observe shell as i...
How to stop stdin while command is running in ash (not bash)? For example: 1. sleep 10 1. type echo hello while sleep is still running 1. observe hello is in stdout after sleep finishes Desired: 1. sleep 10 1. type echo hello while sleep is still running 1. observe shell as if nothing was typed in while sleep was running I expect the solution would be something like: tput ; sleep 10; tput ; This will not be in a shell script (only needs to work with interactive shell).
wjwrpoyob (460 rep)
Apr 12, 2023, 04:22 AM • Last activity: Apr 12, 2023, 06:26 AM
1 votes
2 answers
3696 views
how to move cursor left and right in a router's busybox shell
my router runs asuswrt merlin. the /bin/sh is packaged in BusyBox v1.25.1 (2017-12-02 00:49:46 EST) multi-call binary. my question is how do I move my cursor one word left and right? with bash, i can do `option+left`, `option+right`, which is mapped in terminal to `\033b` and `\033f` respectively. o...
my router runs asuswrt merlin. the /bin/sh is packaged in BusyBox v1.25.1 (2017-12-02 00:49:46 EST) multi-call binary. my question is how do I move my cursor one word left and right? with bash, i can do option+left, option+right, which is mapped in terminal to \033b and \033f respectively. on my router's shell, it just prints a b and an f. so how do i remap shortcuts in shell or what out of the (busy)box shortcut is there? Note 1: i found that busybox supposedly packages ash shell, so my question may be how to move cursor one word with ash shell. Note 2: i tried enabling and disabling the following option to use meta+b and meta+f, no luck using option as meta key Note 3: added apple and ash tags
Jim (111 rep)
Jan 25, 2018, 03:18 PM • Last activity: Mar 13, 2023, 09:51 AM
1 votes
1 answers
1257 views
What happens to arguments passed to bash/ash functions?
[This answer about --](https://unix.stackexchange.com/a/570733/88800) gives a lot of good information about using `--` in POSIX shells and [this answer about passing all arguments to a script](https://stackoverflow.com/a/4824637/1666926) led to the following function: ``` my_echo() { set -x echo $@...
[This answer about --](https://unix.stackexchange.com/a/570733/88800) gives a lot of good information about using -- in POSIX shells and [this answer about passing all arguments to a script](https://stackoverflow.com/a/4824637/1666926) led to the following function:
my_echo()
{
    set -x
    echo $@ " " \"$@\"
    echo ps | grep -- "$@" | grep -v grep | awk '{ print $1 }' 2>/dev/null
    set +x
}

my_echo logread -f
I'm writing this script for OpenWRT. The output from ash shows
+ echo logread -f   "logread -f"
logread -f   "logread -f"
+ ps
+ grep -v grep
+ awk { print $1 }
+ grep -- logread -f
grep: -f: No such file or directory
+ echo

+ set +x
Huh...the quotes I added to the grep command are gone (logread -f is left unquoted). I tried this function in bash
+ echo logread -f ' ' '"logread' '-f"'
logread -f   "logread -f"
++ ps
++ grep --color=auto -- logread -f
++ grep --color=auto -v grep
++ awk '{ print $1 }'
grep: -f: No such file or directory
+ echo

+ set +x
Interesting...maybe my arguments are being parsed separately? To test this theory, I tried:
my_echo "logread -f"
Bash Output:
+ echo logread -f ' ' '"logread' '-f"'
logread -f   "logread -f"
++ ps
++ grep --color=auto -- 'logread -f'
++ grep --color=auto -v grep
++ awk '{ print $1 }'
+ echo

+ set +x
The output of the echo command didn't change (the set version or the actual output but logread -f now seems to be treated as if in double quotes. So...I got lucky because I misinterpreted set's translation of my commands. BUT, my function works now. Ash Output:
+ echo logread -f   "logread -f"
logread -f   "logread -f"
+ ps
+ grep -v grep
+ awk { print $1 }
+ grep -- logread -f
+ echo

+ set +x
And now I'm getting what I expected. It turns out, running my_echo with arguments passed in double quotes (single argument) is the same as
my_echo_new()
{
    echo ps | grep -- "$1" | grep -v grep | awk '{ print $1 }' 2>/dev/null
}

my_echo_new "logread -f"
So...it sure seems like the issue is with working with multiple arguments. What is going on here? Is this a result of the \` or the result of the function call or something else? Why do I need double quotes in both places?
MrMas (295 rep)
May 4, 2020, 05:52 PM • Last activity: Feb 28, 2023, 10:54 AM
2 votes
2 answers
516 views
Better way to retrieve n-th (index) positional parameter value in `ash` then `eval echo \$$n`?
I'd wish the user to `select` a file from a numbered list on screen in a `mkinitcpio` `busybox` `ash` environment. The list needs to be filled/sorted from top to bottom and printed in columns, like: 1) 2017-12-17 3) 2017-12-19 5) 2017-12-21 7) 2017-12-23 9) 2017-12-25 2) 2017-12-18 4) 2017-12-20 6)...
I'd wish the user to select a file from a numbered list on screen in a mkinitcpio busybox ash environment. The list needs to be filled/sorted from top to bottom and printed in columns, like: 1) 2017-12-17 3) 2017-12-19 5) 2017-12-21 7) 2017-12-23 9) 2017-12-25 2) 2017-12-18 4) 2017-12-20 6) 2017-12-22 8) 2017-12-24 I am printing to screen using printf line by line. That is why you would normally use an array. Because busybox ash lacks array support the hack is to use set to create a poor man's array using positional parameters ($1=2017-12-17, $2=2017-12-18, etc.). For now I manage to retrieve the positional parameter value using: file=$(eval echo \$$i) Is there a better way to retrieve the **n-th positional parameter** in **ash**? --- Notes 1. The column listing above is a simplified example, the actual file names do contain time stamps too, like for example 2017-12-27-060056. 2. Mkinitcpio busybox 1.27.2 compile config .
Pro Backup (5114 rep)
Dec 27, 2017, 01:27 PM • Last activity: Dec 22, 2022, 02:38 PM
28 votes
4 answers
20584 views
How to port to bash-style arrays to ash?
Some time ago I have written a bash script which now should be able to run in environment with `ash`. In `bash` it was like : services=( "service1.service" "service2.service" "service3.service" ) for service in "${services[@]}" do START $service done START() { echo "Starting "$1 systemctl start $1 }...
Some time ago I have written a bash script which now should be able to run in environment with ash. In bash it was like : services=( "service1.service" "service2.service" "service3.service" ) for service in "${services[@]}" do START $service done START() { echo "Starting "$1 systemctl start $1 } In reality there are like 40 services in array, and I want to make this transition as painless and clean as possible. Have always been using bashisms. Now I'm in a pinch with the task to make scripts more portable. For portability reasons probably it would be nice to have a pure ash solution. But since I have a pretty robust busybox at my disposal I might sacrifice some portability. Only if readability improves a lot, since "clean" script is a metric too. What would be **portable** and **clean** solution in this case?
metamorphling (572 rep)
Aug 8, 2017, 02:14 AM • Last activity: Sep 16, 2022, 06:16 PM
15 votes
2 answers
31044 views
What is the difference between `ash` and `sh` shell on Linux?
I am new to a lot of tools on Linux. A quick search did not help, I only got more about `bash` or `sh`, and searching for it somehow leans towards `bash` in the search results. There are quite a few different shell types out there, I have even seen `zsh`, thus I guess they are all forks from `sh`. T...
I am new to a lot of tools on Linux. A quick search did not help, I only got more about bash or sh, and searching for it somehow leans towards bash in the search results. There are quite a few different shell types out there, I have even seen zsh, thus I guess they are all forks from sh. There is already a question [What is the difference between using bash and sh to run a script?](https://unix.stackexchange.com/questions/270966/what-is-the-difference-between-using-bash-and-sh-to-run-a-script) that is similar: - but I could not find out what the "a" stands for in a shell - and this question is also not just about running a script, but the shell as such - since I can choose to take ash or sh for a docker container at hand. I remember ash would be more comfortable though still very slim, and I have forgotten why. What is the main difference between ash and sh? size, handling, ...? Base image was python:3-alpine, even the one with the latest tag (2022-07) has both /bin/ash and /bin/sh. There should be a reason why the two are there in the alpine image that is made to be the most compact of all. I call it with docker-compose -f docker-compose-develop.yaml run --rm MY_CONTAINER ash.
questionto42 (587 rep)
Mar 4, 2022, 11:19 AM • Last activity: Jul 5, 2022, 06:53 PM
1 votes
3 answers
8153 views
How to use sh script to send hex data to /dev/ttyUSB0?
I'm working with a paired down embedded Linux installation that does not support bash, only sh across a ssh terminal. I need to send hex data to a connected USB device `/dev/ttyUSB0`. I'm able to do this easily enough with bash (on a desktop installation of Ubuntu 18.04) using `echo -en '\x01\x02\x0...
I'm working with a paired down embedded Linux installation that does not support bash, only sh across a ssh terminal. I need to send hex data to a connected USB device /dev/ttyUSB0. I'm able to do this easily enough with bash (on a desktop installation of Ubuntu 18.04) using echo -en '\x01\x02\x03' > /dev/ttyUSB0, but it seems that the backslash escapes are not supported by sh. Is there another relatively easy (or even not-so-easy) way to do this with sh? Unfortunately, $SHELL --version is not returning anything. Kernel version is 4.1.0.
Jim Fell (285 rep)
May 24, 2022, 10:15 PM • Last activity: May 25, 2022, 07:24 PM
0 votes
1 answers
1866 views
alias in ash - limitation, syntax issue?
I'm running OpenWRT in a NAS (WD-MBL) and 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/rsync...
I'm running OpenWRT in a NAS (WD-MBL) and 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

~$
If I then run the alias I get this:
~$ fschk
>
If I query the alias list from the command line, I see that the one I added is shown differnetly in the printout:
~$ alias
--- snip ---
fschk='df -h|grep -vE '"'"'^/dev/root|tmpfs'"'"'|awk '"'"'{print  '
--- snip ---
:~$
But not in the 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. Any pointers will be greatly appreciated. Thanks in advance. Best, PCL
Groucho (31 rep)
May 8, 2022, 07:10 PM • Last activity: May 8, 2022, 07:40 PM
0 votes
1 answers
339 views
ash - parse a config file line after line
My config file looks as follows: ver 3 file test1.conf ~/etc file test2.conf ~/etc/conf script tst.sh I'd like my script to iterate through all lines prefixed with "file", extract filename and location values and execute some operation. Since now I got: files=$(cat file.conf | grep file) But then I'...
My config file looks as follows: ver 3 file test1.conf ~/etc file test2.conf ~/etc/conf script tst.sh I'd like my script to iterate through all lines prefixed with "file", extract filename and location values and execute some operation. Since now I got: files=$(cat file.conf | grep file) But then I'm not sure how to get into iteration to extract second and third string out of each line.
Kal800 (35 rep)
May 3, 2022, 03:14 PM • Last activity: May 4, 2022, 11:23 AM
2 votes
3 answers
1957 views
How can I expand a list of letters/numbers in ash?
In busybox, the default shell is ash, so some familiar tricks in bash are not available. One thing I would like to do is expand a list of letters, like `{a..z}`, which would expand to `a b c d e f g h i j k l m n o p q r s t u v w x y z` in bash. Is there another way to do this ash?
In busybox, the default shell is ash, so some familiar tricks in bash are not available. One thing I would like to do is expand a list of letters, like {a..z}, which would expand to a b c d e f g h i j k l m n o p q r s t u v w x y z in bash. Is there another way to do this ash?
Paul (380 rep)
Mar 9, 2018, 05:03 PM • Last activity: Mar 19, 2022, 05:56 PM
1 votes
2 answers
2036 views
ssh, start a specific shell (ash), and source your environment on the remote machine
This is a kind of follow-up question to this question: https://unix.stackexchange.com/q/20729/114401, except more-specifically regarding `ash`, and focused on the fact that sourcing a .bashrc file as part of starting the shell in the ssh session doesn't work for me. I'm on an embedded Linux device w...
This is a kind of follow-up question to this question: https://unix.stackexchange.com/q/20729/114401 , except more-specifically regarding ash, and focused on the fact that sourcing a .bashrc file as part of starting the shell in the ssh session doesn't work for me. I'm on an embedded Linux device which has a busybox version of sh and ash, but there is no bash. We share a common username (root), and a common execution environment. I'd like to have a few custom aliases and a custom PS1 Prompt String 1 variable, however. Here is an example normal ssh session. Note that I'm using sshpass to pass my password to ssh, with my password stored in the ~/pw file. You can see that the default shell is -sh and there are no aliases. The default PS1 prompt string also shows no path. > $ sshpass -f ~/pw ssh root@192.168.0.2 > [root@device]$ echo $0 > -sh > [root@device]$ alias > [root@device]$ The device has no bash, but it does have ash, which apparently is bash-like. So, I want to make that my shell as I ssh in. I also want to copy Ubuntu's default ~/.bashrc file, located in /etc/skel/.bashrc on the Ubuntu machine I'm ssh-ing _from_, to the device at /tmp/.bashrc so I can source it, and I want my ssh command to do that. I can't copy to ~/.bashrc on the remote device because the home dir is read-only. I tried the following, but get the following error: cmd:
sshpass -f ~/pw scp /etc/skel/.bashrc root@192.168.0.2:/tmp/.bashrc \
&& sshpass -f ~/pw ssh -t root@192.168.0.2 '. /tmp/.bashrc'
result: > Connection to 192.168.0.2 closed. No ssh session was established. I then tried the following command, with the following result, showing that sourcing did not work, although the ash shell was entered. > $ sshpass -f ~/pw scp /etc/skel/.bashrc root@192.168.0.2:/tmp/.bashrc \ > && sshpass -f ~/pw ssh -t root@192.168.0.2 '. /tmp/.bashrc; ash' > ~ # echo $0 > ash > ~ # alias > ~ # I can run . /tmp/.bashrc manually now though, and it works fine. Notice how after sourcing, which works, I have an improved prompt string and new aliases: > ~ # . /tmp/.bashrc > ash: /tmp/.bashrc: line 16: shopt: not found > ash: /tmp/.bashrc: line 24: shopt: not found > ash: /tmp/.bashrc: line 111: shopt: not found > root@device:~# alias > l='ls -CF' > alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '"'"'s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'"'"')"' > la='ls -A' > ll='ls -alF' You also see the ash errors from line 16, 24, and 111 due to shopt not being found. Even if I comment those out in the .bashrc file I send over, the results as shown above are still the same. **How can I get my above command to work? I'd like it to ssh in, set the shell to something more like bash, and source my /tmp/.bashrc file I scp'ed over.** --- On a similar embedded device which _does_ have bash installed, this cmd works perfectly, [as I document in my repo here](https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh#command) :
sshpass -f ~/pw scp /etc/skel/.bashrc root@192.168.0.2:/tmp \
&& sshpass -f ~/pw ssh -t root@192.168.0.2 'bash --rcfile /tmp/.bashrc'
For bash, using bash --rcfile /tmp/.bashrc at the end of the ssh cmd is what I need. But, for the device withOUT bash, I need help getting this behavior with ash or similar.
Gabriel Staples (2972 rep)
Nov 11, 2021, 10:28 PM • Last activity: Nov 11, 2021, 10:52 PM
Showing page 1 of 20 total questions