Hot answers tagged

52

You could use the -o switch to specify your output format: $ ps -eo args From the man page: Command with all its arguments as a string. Modifications to the arguments may be shown. [...] You may also use the -p switch to select a specific PID: $ ps -p [PID] -o args pidof may also be used to switch from process name to PID, hence allowing the use of -...


43

This answer is for others out there that DocSalvager's answer doesn't work for. I followed DocSalvager's use of ls to find the correct hard drive partition. In my case it was (hd0,msdos5). Then I executed the following commands to get back to the normal grub boot loader screen. grub rescue> set boot=(hd0,msdos5) grub rescue> set prefix=(hd0,msdos5)...


33

By default, BusyBox doesn't do anything special regarding the applets that it has built in (the commands listed with busybox --help). However, if the FEATURE_SH_STANDALONE and FEATURE_PREFER_APPLETS options are enabled at compile time, then when BusyBox sh¹ executes a command which is a known applet name, it doesn't do the normal PATH lookup, but instead ...


28

I think sort file1 file2 | uniq aaaaaa bbbbbb cccccc mmmmmm nnnnnn yyyyyy zzzzzz will do what you want. Additional Documentation: uniq sort


28

Recovering from a grub rescue crash ... grub rescue> does not support cd, cp or any other filesystem commands except its own variation of ls which is really a kind of find command. So first, had to find the partition with the /boot directory containing the vmlinuz and other boot image files... grub rescue> ls (hd0,4) (hd0,3) (hd0,2) (hd0,1) ...


23

1) You shouldn't manually update your resolv.conf, because all changes will be overwritten by data that your local DHCP server provides. If you want it to be static, run sudo dpkg-reconfigure resolvconf and answer "no" to dynamic updates. If you want to add new entries there, edit /etc/resolvconf/resolv.conf.d/base and run sudo resolvconf -u, it will append ...


14

With GNU date you can do it as simple as this: date --date="3min" But busybox seems not so smart (yet). The only reliable solution I came up with using bb is: busybox date -D '%s' -d "$(( `busybox date +%s`+3*60 ))" (you don't need the busybox parts if there is no other date implementation present) If you want a formatted output, you could add this ...


14

On busybox, "ps" doesn't have a "-o" option, but "ps l" includes the RSS column. If the underlying O/S is Linux, you can also get more specific details for a given process from: cat /proc/PID/status The output looks like this: Name: ash State: S (sleeping) Tgid: 1990 Pid: 1990 PPid: 1 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 ...


12

read is a shell builtin (it couldn't set a shell variable if it were not). So, if your busybox sh is based on ash, it's: while IFS= read -r line <&3; do printf '%s\n' "$line" done 3< "$InputFile" Like in any POSIX shell. But like with any shell, using while read loops to process text is generally bad shell scripting practice. Above, you need: ...


12

Try something like this: (example output from busybox on OpenWrt on one of my routers) root@ap8:~# xargs -0 printf '%s\n' </proc/991/cmdline /usr/sbin/uhttpd -f -h /www -r ap8 -x /cgi-bin -u /ubus -t 60 -T 30 -k 20 -A 1 -n 3 -N 100 -R -p 0.0.0.0:80 -p [::]:80 /proc/$PID/cmdline contains the arguments of process $PID like a C-ish strings one after ...


11

OK, I did a lot of extensive research and I found out what was wrong. Let's start one by one: When we use initramfs boot scheme the first process which the kernel invokes is the /init script. The kernel will never try to execute /sbin/init directly. /init is assigned process identifier 1. This is very important! The problem now is that /sbin/init can only ...


11

Method #1 - Using ps You could use ps -eaf | grep 1234. Example $ ps -eaf | grep 28865 saml 28865 9661 0 03:06 pts/2 00:00:00 bash -c sleep 10000; while [ 1 ];do echo hi;sleep 10;done saml 28866 28865 0 03:06 pts/2 00:00:00 sleep 10000 NOTE: Busybox's ps doesn't include the -eaf switches as shown above from a typical ps that's included ...


11

-mtime is a standard predicate of find (contrary to -delete) but it looks like you have a stripped down version of busybox, where the FEATURE_FIND_MTIME feature has been disabled at build time. If you can rebuild busybox with it enabled, you should be able to do: find . -mtime +6 -type f -exec rm -f {} + Or if FEATURE_FIND_DELETE is also enabled: find . -...


10

while read VAR is probably best here, as it handles per-line input. You can redirect it from a file, e.g.: while IFS= read -r THELINE; do echo "..$THELINE" done </path/to/file That'll give you each line prepended with ".." For your example case: while IFS= read -r opt; do #somestuff $opt done </path/to/file See Why is `while IFS= read` used ...


10

In just one command without any pipe : sort -u FILE1 FILE2 search Suppress duplicate lines -> http://www.busybox.net/downloads/BusyBox.html


10

BusyBox has two shells, ash and hush. To see which one you have, run type chdir: ash has it as a builtin (synonymous with cd), hush doesn't. Both have an optional prompt expansion feature. Ash's is enabled by activating the ASH_EXPAND_PRMT feature at compile time, while hush requires FEATURE_EDITING_FANCY_PROMPT. When that feature is present, in ash the ...


10

[[...]] is a Korn shell construct also supported by bash and zsh but otherwise not a standard sh one (and not supported by any other shell). busybox sh is based on ash that implements a subset of the POSIX specification of sh (in the POSIX locale, it is compliant for the most part) with very few extensions, and in particular, not this one. 2019 edit. a ...


9

This isn't related to BusyBox. BusyBox is a set of unix utilities designed for low-resource environments such as routers. Your router's root filesystem is mounted read-only because it's stored on SquashFS, a compressed filesystem which cannot be written to. A SquashFS filesystem is compressed in one go when the filesystem is built and cannot be modified ...


9

SIGTERM is the signal that is typically used to administratively terminate a process. That's not a signal that the kernel would send, but that's the signal a process would typically send to terminate (gracefully) another process. That's the signal that is sent by default by the kill, pkill, killall, fuser -k... commands. That's the signal that is sent to ...


9

Depending on your implementation/version of watch, it may not start a shell to interpret a command line, but instead runs a command that takes as argument the arguments it received itself. So, in that case, if you need it to run a shell command line, you need to start a shell explicitly as in: watch sh -c 'find . | wc -l' See also the inotifywait -rm . ...


9

For buildroot all your scripts must be placed in $path_to_buildroot/output/target/etc/init.d before build image. In my case this directory contains rcS and few scripts named S[0-99]script_name. So you can create your own start\stop script. rcS: #!/bin/sh # Start all init scripts in /etc/init.d # executing them in numerical order. # for i in /etc/init.d/S??...


9

Append shutdown -r 60 to /etc/rc.local.


8

Picking up where Arto left off here, this is entirely possible, even without mv -T, you just need to create a new symlink with the same name as the target directory and mv it into the parent directory of your target: mkdir -p tmp/real_dir1 tmp/real_dir2 touch tmp/real_dir1/a tmp/real_dir2/a # start with ./target_dir pointing to tmp/real_dir1 ln -s tmp/...


8

You can use a symlink, I just tried this to be sure. Since the stuff in /tmp is impermanent, that means you will have to create the file at boot before dhcpcd runs. touch /tmp/dhcpcd.resolv.conf ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf I included the ln bit by way of illustration but note that you don't have to create the symlink every time at boot; ...


8

ps -o pid,user,vsz,rss,comm,args The 4th column (rss) is the resident set size, the non-swapped physical memory used by a task, in kiloBytes.


8

On OpenWRT, date is busybox, which has limitations, but this is not strictly one of them. The underlying problem is that the libc (uClibc) does not support this GNU strftime extension. (Though neither does glibc, more on that below.) You should have lua by default, but that won't help without some other non-default modules. hwclock calls gettimeofday() for ...


8

Wow, that has to be the first time this century that I've heard rx referred to as a "great little utility"! :-) Yet we can still dust the cobwebs off those old commands. XMODEM: rx for receiving, sx for sending. YMODEM: rb for receiving, sb for sending. ZMODEM: rz for reveiving, sz for sending.


8

A lot depends on what you have in your busybox and other commands. I don't think your limited wget can be used; however, a simple POST request can be emulated with just a cat, provided you can open a socket, e.g. with nc (netcat, socat), telnet, or even with a full version of bash, as it can do a connect, as shown below: On another machine, use curl to do ...


8

for i in *; do tail -2 "$i" | head -1; done >>file.txt That should be sh (and hence Busybox) compatible, but I don't have a non-bash available for testing ATM. Edited in accord with helpful comments.


8

is there a way to safely test it? With the generic x86 openwrt image: Most commands are not built-in, but some are, like echo and printf. A binary file with arbitrary contents can be created using printf, but chmod +x will be a problem.


Only top voted, non community-wiki answers of a minimum length are eligible