Tag Info

Hot answers tagged

6

How about: while read code device state junk; do if [[ $code == $message ]]; then echo "Translated: $device-$state" fi done <CODE-LIST.txt Using extra processes (i.e. forking awk everytime) will slow it a lot. read will read multiple fields, separated by $IFS (default value is all white space). The last variable listed will receive the ...


4

Could use awk for the whole thing. Awk is also far quicker than while read loops. awk -vM="$Message" '$1==M{print "Translated:",$2"-"$3}' CODE-LIST.txt Explanation -vM="$Message" - Create a variable named M with the value from $Message $1==M - If the first field is equal to variable M($Message) {print "Translated:",$2"-"$3} - ...


4

The hostname command doesn't store the name anywhere but kernel memory. How the system decides what its name is at boot time depends on how the system is configured. Options range from reading a name from a file, to using DNS or /etc/hosts to set the name after a suitable network interface has been brought up.


4

hostname(1) is just a front-end to the sethostname(3) system call, which basically writes the hostname to where the kernel expects it to be stored. If you want the change to be permanent, as per general Unix philosophy you have to store it yourself. The precise location however depends heavily on your init system. For instance, OpenBSD’s init reads the ...


4

Process substitution results in a special file (like /dev/fd/63 in your example) that behaves like the read end of a named pipe. This file can be opened and read, but not written, not seeked. Commands that treat their arguments as pure streams work while commands that expect to seek in files they are given (or write to them) won't work. The kind of command ...


3

Commands within your prompt command function alter PIPESTATUS, bash saves and restores PIPESTATUS (and $?) after your prompt command, see the description of the intended behaviour here. The trick is to save $PIPESTATUS[] (and/or $?) in the very first statement of your function, after that the original values are overwritten. function myprompt() { ...


3

Install the inotify-tools package on your distribution. Use the command inotifywait to create a continuous lookup on the desired directory. Ex: inotifywait -m -r -e create /src_dir. This tool can watch other aspects of the filesystem(attributes change, close write, move, delete), so, lets stick with the file creation thing. Preapare the notification and ...


3

In my experience, no. The system will panic once the root device disappears. You can verify this in your particular situation if you want using a virtualization application like VirtualBox, qemu, kvm, etc. These will allow you to remove a virtual HDD from the machine and observe the result on the system. If you're interested in making a bootable USB drive ...


3

It turns out the initrd generated by Debian's live-build (and to my surprise, accepted by the kernel) is actually the concatenation of two images: a CPIO archive containing microcode updates to be applied on the processor; a gzip-ed cpio archive, which actually contains the initrd file tree (with the /etc /bin /sbin /dev ... directories that were ...


3

It could be untrusted X11 forwarding timeout. Using the ForwardX11Timeout option with a large timeout may help, as suggested in https://bugzilla.mindrot.org/show_bug.cgi?id=1718 (I got this problem in the past, but IIRC, it disappeared after some upgrade).


3

For general purpose tabular alignment, you want the column utility. For example: ( printf 'PID\tUSER\tAPPNAME\n' printf '%s\t%s\t%s\n' "1" "john" "foo bar" printf '%s\t%s\t%s\n' "12345678" "someone_with_a_long_name" "pop tart" ) | column -t -s $'\t' Results in: PID USER APPNAME 1 john foo bar ...


3

The configuration of the Linux kernel eventually defines what the preprocessor directives for the C compiler are. The output from the preprocessed sources should be close to what you are looking for, although there also might be dead code that is optimised out by the compiler. The gcc compiler can be told to generate the preprocessed output to stdout using ...


2

Also can this script be optimized into one line command? I'd consider using the -o option of the ps command to output (as far as possible) only the fields of interest, and then post-processing that to match the java processes and specific command argument(s) that you require - something like ps -u $USER -o uname=,pid=,args= | gawk -vOFS='\t' ...


2

Here's another one using the output formatting from ps: #!/usr/bin/sh -f printf '%-8.7s%-8s%s\n' $( ps -o uname=UID,pid=PID,args=APPNAME | sed -n '1p;s/\( [0-9]* \).*\(-Dapp.name=[^ ]*\).*/\1\2/p' ) Based on its format string, for every 3 of its arguments printf will print: The first space-padded on the right to a standard tab-width of 8 ...


2

make a new file in /bin called treesize chmod +x /bin/treesize paste this in it. #/bin/sh du -k --max-depth=1 | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 } $1 = sprintf("%.1f %s", $1, Units[u]); ...


2

Your script does not have /tmp/console_test opened, the cat process does. Your script is reading from a pipe that is connected to the cat process; that's what you're seeing in your question. Search for the cat process and check that one out. You probably want something like this: while read x; do echo "received $x" eval "$x" done < ...


2

In order to run a program, it must be in RAM. During thrashing, all programs get swapped out of RAM and then have to be swapped in again before they can run. Additionally, for many (but not all) input events, there must be a round trip between your X11 server and your window manager, and the window manager may try to trigger additional events. And since you ...


2

You can check if your MAC address really changed by using ifconfig and look the HWAddr value behind the appropriate device name. What has worked for me on Mint, without any additional programs to install is using ifconfig: sudo ifconfig eth0 down sudo ifconfig eth0 hw ether 00:01:02:03:04:05 sudo ifconfig eth0 up or in more permanent fashion by adding ...


2

The -exec operand of find evaluates to true if the command succeeds (i.e. returns zero) and false if it fails (returns nonzero), so you can use the success/failure of grep as part of the expression used by find. Together with find's ! operand, which negates the following operand, you can search for files for which one grep command succeeds and another grep ...


2

I think your approach is correct, and tracking the cookie is a robust way of doing this. However, the only place in the source of inotify-tools (3.14) that cookie is referenced is in the header defining the struct to match the kernel API. If you like living on the edge, this patch applies cleanly to 3.14 and adds a %c format specifier for the event cookie ...


2

Replace for file_name in `ls -Al ${source_folder}*"${file_pattern}"*.csv` With: for file_name in "${source_folder}"*"${file_pattern}"*.csv The output of a command in backticks, as in the first form above, is subject to word-splitting. The second form above does not use backticks. It will, by contrast, work with any file name, even ones that contain ...


2

Make sure you are not running out of disk space Run df and make sure you have sufficient disk space, if you are low on disk space remove unnecessary files from your system: $ df -h Make sure ~/.Xauthority owned by you Run following command to find ownweship: $ ls -l ~/.Xauthority Run chown and chmod to fix permission problems [replace user:group with ...


2

As indicated in the comments, your system is using systemd for service management. Systemd is a replacement for the traditional SysVinit. It also bundles in a lot of other things such as a syslog collector. In this case, to get access to your logs, you need to use the journalctl command. $ journalctl If you want to see only the sshd logs, you can pass a ...


2

You can install ImageMagick and use the identify tool with -verbose, for example: for f in *.jpg *.jpeg *.JPG *.JPEG *.mp4 *.MP4; do echo $f identify -verbose "$f"|grep exif:DateTime echo done Kepler22b-artwork.jpg Kepler-62f_with_62e_as_Morning_Star.jpg exif:DateTime: 2013:04:08 10:45:44 logo.jpg P1050030.JPG exif:DateTime: 2013:11:01 ...


2

Take a look at this related U&L Q&A titled: Where does uname get its information from?. Information such as the hostname persists within a data structure within the Linux kernel, while the system is running. During a system's boot this information can be reattained through a variety of mechanisms that is typically distro specific. If you look at the ...


2

The & at the end of your command makes it run in the background. Therefore, when you quit your SSH session, it will keep running. Also read http://superuser.com/a/152695/228108 (the comments mainly).


1

In looking through the manual it only seems to pertain to theming. This excerpt had a bit more on the subject. excerpt - http://www.gnu.org/software/grub/manual/grub.html#menuentry The boot menu where GRUB displays the menu entries from the “grub.cfg” file. It is a list of items, where each item has a title and an optional icon. The icon is selected ...


1

So, based on @wurtel's answer and the research I've done, here's the script and the steps I came up with. 1) Unmount the "home" partition umount /dev/mapper/APP05-home 2) Resize the "home" filesystem to a size of 2G resize2fs -p /dev/mapper/APP05-home 2G 3) Reduce the size of the "home" logical volume to 2,1G (the volume needs to be a little bit bigger ...


1

Ignore the first "rootfs" entry, the real mount is shown by the /dev/mapper/APP05-root line. To reduce filesystem size, first shrink the filesystem size with resize2fs, and then use lvresize to reduce the device size. To increase the size, use the utilities in reverse order. Reducing the filesystem size needs to be done while the filesystem is not mounted. ...


1

Parsing versions Hackey way For the first part, I'd query RPM for the particular version info like so. $ rpm -qi vim-enhanced | grep Version Version : 7.4.417 You can then parse this out like so: $ rpm -qi vim-enhanced | awk -F': ' '/Version/ {print $2}' 7.4.417 This can be captured into a variable like so: $ RPM_VERSION=$(rpm -qi vim-enhanced | ...



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