This is golden: ShellCheck – shell script analysis tool.
It checks your shell scripts, either on-line or off-line (brew install shellcheck for Mac, apt, etc for Linuces)
–jeroen
via: regex – Read file line by line with bash script – Stack Overflow
Posted by jpluimers on 2017/03/09
This is golden: ShellCheck – shell script analysis tool.
It checks your shell scripts, either on-line or off-line (brew install shellcheck for Mac, apt, etc for Linuces)
–jeroen
via: regex – Read file line by line with bash script – Stack Overflow
Posted in bash, Development, Scripting, Sh Shell, Software Development | Leave a Comment »
Posted by jpluimers on 2017/03/07
Nice: “you can get both aliases and functions with compgen -a -A function”
It uses the compgen completion generator. Simply brilliant (:
Source: bash – how do I list the functions defined in my shell? – Stack Overflow
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/02/26
Cheatsheet:
A; B Run A and then B, regardless of success of A A && B Run B if A succeeded A || B Run B if A failed A & Run A in background.
Source: bash – Which one is better: using ; or && to execute multiple commands in one line? – Ask Ubuntu [WayBack]
Thanks Jack [WayBack] for the initial answer ubfan1 [WayBack] for getting the formulation right, Hatshepsut [WayBack] for making it a readable cheat-sheet and leftaroundabout [WayBack] for making this brilliant addition using parenthesis which can be used for all permutations:
(A && B) & In the background: run B if A succeeded
–jeroen
Posted in bash, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/02/08
On most systems, I use bash as shell, but not all systems have it, for instance the shell.xs4all.nl server uses tcsh and ESXi 4+ uses a very limited ash shell from busybox (ESX 4 had bash though).
There is this huge script that covers many shell and operating system versions (even DOS, Windows) and interpreters (python, ruby, php, etc) what shell is this which I got through Stéphane Chazelas‘s answer in linux – determine shell in script during runtime – Unix & Linux Stack Exchange
I wanted a shorter thing that works in current Linux, BSD, OS X and ESXi versions.
Some very short scripts are less reliable, for instance echo $SHELL looks nice, but isn’t always set.
Similar for echo $0 which will fail for instance if it shows as sh but in fact is a different shell in disguise.
This works for bash, tcsh and busybox sh, is a bit more precise than getting $0. It’s based on HOWTO: Detect bash from shell script – Stack Overflow:
lsof -p $$ | awk '(NR==2) {print $1}'
But on ESXi it shows this because lsof doesn’t take any parameter there and just dumps all information:
----------+---------------------+---------------------+--------+------------------
It’s because lsof on ESXi always shows this header where Cartel and World aren’t exactly well documented:
Cartel | World name | Type | fd | Description
----------+---------------------+---------------------+--------+------------------
Empirically for non VM related processes, it looks like the Cartel is the PID and World name the command.
On Linux and BSD based systems, the header looks like this, so command and PID are reversed in ESXi:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
This command then works on both ESXi, OS X, Linux and BSD assuming you can word search for the PID and noting that PID/command will be reversed on ESXi as compared to OSX/Linux/BSD:
lsof -p $$ | grep -w $$ | awk '(NR==2) {print $1,$2}'
–jeroen
Posted in Apple, bash, BSD, Development, iMac, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, OS X 10.10 Yosemite, OS X 10.11 El Capitan, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/01/31
pi-hole – A black hole for Internet advertisements (designed for Raspberry Pi)
Works on most Debian distributions as well. Hopefully on opensuse one day as well.
Source: pi-hole/pi-hole: A black hole for Internet advertisements (designed for Raspberry Pi)
Not exactly the nicest way of installing though:
curl -L install.pi-hole.net | bash
Source: Pi-Hole: A Black Hole For Internet Advertisements
Source: In the past year, a similar threat has begun to emerge on mobile devices:…
Note that any ad-block mechanism needs curation to white/black list some stuff. But: who does that and who watches the curators?
via:
Some more links for when you get this going:
As all raspbian hosts advertise their hostname as raspberrypi it is confusing to set them apart, so I changed the hostname in these files:
/etc/hostname
/etc/hosts
/etc/wicd/wired-settings.conf
/etc/wicd/wireless-settings.conf
Then rebooted (probably could have done sudo /etc/init.d/hostname.sh) to force the new hostname to be used everywhere.
Note that pi-hole by default converts the DHCP assigned address on eth0 to a static one. This makes it harder to use pi-hole in these situations:
To get going I:
wlan0 in the ifconfig listwicd-curses to work: it would only detect half of the WiFi networks that iwlist wlan0 scan detects.sudo iwlist wlan0 scan | grep ESSID scan to get a list of networks and their (E)SSID names/etc/wpa_supplicant/wpa_supplicant.conf and correct the value for ssid to the ESSID (keep the double quotes around it) and psk to the password for that ESSID (also keep the double quotes around it)sudo ifdown wlan0 and sudo fup wlan0 to force a WiFi connection refreshifconfig for wlan0
network={
ssid="The_ESSID_from_earlier"
psk="Your_wifi_password"
}
–jeroen
Posted in *nix, bash, Development, Linux, openSuSE, Power User, Scripting, Software Development, SuSE Linux, Tumbleweed | 1 Comment »
Posted by jpluimers on 2017/01/10
Getting the local IP (actually IPs, but most hosts only have a single IP):
# OS X:
alias whatismylocalip='ifconfig | sed -En '\''s/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'\'''
# Linux:
alias whatismylocalip='ip a | sed -En '\''s/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'\'''
I got them via bash – How to I get the primary IP address of the local machine on Linux and OS X? – Stack Overflow
Mac OS X and BSD have ifconfig, but most Linux distributions don’t use ifconfig any more in favour of iproute2, so you use ip a (which is shorthand for ip address show) there.
Their output is similar enough for the sed to work, though. Which surprised be because I didn’t know about the -E option (it lacks in the manual Linux page but it is in the Mac OS X one) which enables POSIX extended regular expressions. In Linux this is documented as -r, but -E also works.
I learned this through the Sed – An Introduction and Tutorial which compares the various versions of sed which also explains about the -n doing no printing.
–jeroen
Posted in *nix, *nix-tools, Apple, bash, bash, Development, Linux, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, openSuSE, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development, SuSE Linux, Tumbleweed | Leave a Comment »
Posted by jpluimers on 2016/12/06
Scripts are soooo coool.
I remember doing similar things in Windows, but couldn’t find the batch files any more. There is an example (thanks Rob W for answering, thanks Suchipi for asking) that works in Mac/Linux:
ImageMagick (Windows/Mac/Linux) contains a command-line tool called convert that can be used for many things, including packing multiple images in one icon:
convert 16.png 32.png 48.png 128.png 256.png -colors 256 icon.icoThe previous command takes 5 PNG images, and combines them into a single .ico file.
Unlike the other answers, this method can easily be used in batch scripts to automatically generate several icon files. In one of my projects, I have a single vector image (SVG), and use Inkscape to generate png’s of various sizes, followed by convert to create a icon container. This is a reduced example (in a bash script):
#!/bin/bash for size in 16 32 48 128 256; do inkscape -z -e $size.png -w $size -h $size icon.svg >/dev/null 2>/dev/null done convert 16.png 32.png 48.png 128.png 256.png -colors 256 icon.ico
–jeroen
via:
Posted in bash, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2016/11/12
Calling C libraries from bash with virtual automatic data conversion based on symbol info in the .so files.
Source: Tavis Ormandy: Just when you thought we couldn’t take this any further…
–jeroen
Posted in bash, C, Development, gcc, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2016/11/01
If you see this in journalctl after boot in a VM, then you likely want to disable piix4 smbus device detection:
Jul 07 23:02:47 revue systemd-udevd[507]: maximum number (136) of children reached Jul 07 23:02:47 revue systemd-udevd[507]: maximum number (136) of children reached ... Jul 07 23:02:47 revue systemd-udevd[507]: maximum number (136) of children reached Jul 07 23:02:47 revue systemd-udevd[507]: maximum number (136) of children reached ... Jul 07 23:02:47 revue kernel: piix4_smbus 0000:00:07.3: SMBus Host Controller not enabled!
The solution is to add one line to /etc/modprobe.d/50-blacklist.conf (well: maybe [WayBack] add a comment line as well):
blacklist i2c_piix4
via:
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, Linux, openSuSE, Power User, Scripting, Software Development, SuSE Linux, Tumbleweed | 2 Comments »
Posted by jpluimers on 2016/10/25
I’m using Linux (centos) machine, I already connected to the other system using ssh. Now my question is how can I copy files from one system to another system?
Source: How to copy files from one machine to another using ssh – Unix & Linux Stack Exchange
Nice question, uh? In my opinion the best answer is “Use scp to avoid going through hoops with complex configurations to re-use your existing ssh connection” like this:
To copy a file from
BtoAwhile logged intoB:scp /path/to/file username@A:/path/to/destinationTo copy a file from
BtoAwhile logged intoA:scp username@B:/path/to/file /path/to/destinationSource: DopeGhoti answering How to copy files from one machine to another using ssh – Unix & Linux Stack Exchange
Instead the question is marked duplicate of SSH easily copy file to local system – Unix & Linux Stack Exchange where (contrary to the ‘easily’ part of the question) go through hoops and loops with all kinds of fancy ssh settings and port forwards.
For recursive, use the -r option, as per [WayBack] shell – How to copy a folder from remote to local using scp? – Stack Overflow:
scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/From
man scp(See online manual)
-r Recursively copy entire directories
Related:
Posted in *nix, *nix-tools, bash, Communications Development, Development, Internet protocol suite, Power User, Scripting, Software Development, SSH, TCP | Leave a Comment »