Archive for the ‘*nix-tools’ Category
Posted by jpluimers on 2020/02/18
Excellent answer at [WayBack] linux – Bash: Command grouping (&&, ||, …) – Stack Overflow by Charles Duffy:
Operator precedence for && and || is strictly left-to-right.
Thus:
pwd; (ls) || { cd .. && ls student/; } && cd student || cd / && cd ;
…is equivalent to…
pwd; { { { (ls) || { cd .. && ls student/; }; } && cd student; } || cd /; } && cd ; }
…breaking that down graphically:
pwd; { # 1
{ # 2
{ (ls) || # 3
{ cd .. && # 4
ls student/; # 5
}; # 6
} && cd student; # 7
} || cd /; # 8
} && cd ; # 9
pwd happens unconditionally
- (Grouping only)
ls happens (in a subshell) unconditionally.
cd .. happens if (3) failed.
ls student/ happens if (3) failed and (4) succeeded
- (Grouping only)
cd student happens if either (3) succeeded or both (4) and (5) succeeded.
cd / happens if either [both (3) and one of (4) or (5) failed], or [(7) failed].
cd happens if (7) occurred and succeeded, or (7) occurred and succeeded.
Using explicit grouping operators is wise to avoid confusing yourself. Avoiding writing code as hard to read as this is even wiser.
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2020/02/03
A few notes for managing the users that should be allowed to send mail via sendmail using TLS authentication.
Most of it is derived/summarised for [WayBack] SMTP AUTH in sendmail 8.10-8.13 and [WayBack] Creating Users for a Postfix-Based Mail Relay – Scott’s Weblog – The weblog of an IT pro specializing in cloud computing, virtualization, and networking, all with an open source view
- Verify your sendmail allows TLS:
# sendmail -d0.1 -bv | grep SASL
NETUNIX NEWDB NIS NISPLUS PIPELINING SASLv2 SCANF SOCKETMAP
- The list of TLS authentication users differs from the ones in
/etc/passwd
- The tools and files manage if the output is
SASLv2 or older. For SASLv2 they are:
/etc/sasldb2 has the users/passwords
sasldblistusers2 lists the users
saslpasswd2 manages users
For instance, this commands creates a new user for use with sendmail:
# saslpasswd2 -c -u example.org firstname.lastname
Password:
Again (for verification):
sasldblistusers2
firstname.lastname@example.org: userPassword
cat /etc/sasldb2
....................firstname.lastname@example.orguserPassword
For future reading:
I thought I needed this so I could add an alias @pluimers.com to my gmail box, as I read only the accepted answer at [WayBack] Add new alias to Gmail without SMTP (forwarding-only address) – Web Applications Stack Exchange pointing to:
I should have read the second answer at [WayBack] Add new alias to Gmail without SMTP (forwarding-only address) – Web Applications Stack Exchange:
As of writing, however, you can simply use the Gmail SMTP server, as long as you use [WayBack] Google two-step authentication.
So just for completeness, the full steps:
- Gmail settings, Accounts and Import tab.
- Add another email address you own
- Type name and email address to be added.
- For SMTP Server, put
smtp.gmail.com
- For Username, your full Gmail address including
@gmail.com
- For password, provide an App Password generated in Google Accounts at https://security.google.com/settings/security/apppasswords
- Leave Secured connection using TLS selected as is.
- Add Account
–jeroen
Posted in *nix, *nix-tools, Power User, sendmail | Leave a Comment »
Posted by jpluimers on 2020/01/20
When you look at how to find listed cron jobs, usually the answer is cron -l or cron -u username -l.
However, on OpenSuSE systems, cron jobs can be in different places, and the sysconfig settings have influence on them too.
These files and directories all influence cron:
Directories:
/etc/cron.d/
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/
Files:
/etc/sysconfig/cron
/etc/init.d/rc2.d/K01cron
/etc/init.d/rc2.d/S14cron
/etc/init.d/rc3.d/K01cron
/etc/init.d/rc3.d/S14cron
/etc/init.d/rc5.d/K01cron
/etc/init.d/rc5.d/S14cron
/etc/init.d/cron
/etc/news/crontab.sample
/etc/pam.d/crond
/etc/systemd/system/multi-user.target.wants/cron.service
/etc/omc/srvinfo.d/cron.xml
/etc/cron.deny
/etc/crontab
Most are available for other Linux distributions as well, but each one might have slightly different configurations (especially for the directories). Some background reading:
Some details:
- The
crontab -l will only list what is in /etc/crontab.
- These directories are influenced by
/etc/sysconfig/cron, especially the DAILY_TIME variable (see below) for the daily jobs.
All of the directories are checked every 15 minutes through /usr/lib/cron/run-crons:/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/
- That script then uses these files for checking when to run:
/var/spool/cron/lastrun/cron.weekly
/var/spool/cron/lastrun/cron.daily
/var/spool/cron/lastrun/cron.hourly
The DAILY_TIME variable:
## Type: string
## Default: ""
#
# At which time cron.daily should start. Default is 15 minutes after booting
# the system. Example setting would be "14:00".
# Due to the fact that cron script runs only every 15 minutes,
# it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time
# you set.
DAILY_TIME=""
–jeroen
Posted in *nix, *nix-tools, cron, Linux, openSuSE, Power User, SuSE Linux, Tumbleweed | Leave a Comment »
Posted by jpluimers on 2019/12/23
Posted in *nix, *nix-tools, Development, Encoding, Google, GoogleWebP, Image Editing, Power User, Software Development, The Gimp, WebP | Leave a Comment »
Posted by jpluimers on 2019/12/20
Cool: Magic SysRq key – Wikipedia
The magic SysRq key is a key combination understood by the Linux kernel, which allows the user to perform various low-level commands regardless of the system’s state. It is often used to recover from freezes, or to reboot a computer without corrupting the filesystem.[1] Its effect is similar to the computer’s hardware reset button (or power switch) but with many more options and much more control.
Sometimes reading fluffy fluff posts teaches you new things, so be sure to read this one:
[WayBack] I just got trolled by my cat, hard. Last night i left my linux laptop open and running while watching TV in the other room. I came back to find Marley … – Stephen Shirley – Google+
…
I started looking through the kernel logs from last night, to see if there was any indication of the issue starting. And then i saw it. One innocent line that said:
Dec 18 21:26:52 x240 kernel: [373001.156356] sysrq: SysRq : Emergency Remount R/O
The fluffy dumbass had somehow hit the Sysrq [0] key combo to mount all filesystems read-only. This is an old, low-level when-all-else-fails facility for dealing with an linux unresponsive system, and fluff-for-brains Marley had somehow hit alt+fn+s+u.
Sigh.
[0] https://en.wikipedia.org/wiki/Magic_SysRq_key
Via: [Archive.is] I just got trolled by my cat, hard. Last night i left my linux laptop open and running while watching TV in the other room. I came back to find Marley … – Kristian Köhntopp – Google+
–jeroen
Posted in *nix, *nix-tools, Keyboards and Keyboard Shortcuts, Linux, Power User | Leave a Comment »
Posted by jpluimers on 2019/12/03
Many unix tools that report sizes in bytes can convert them to either IEC or SI readable formats.
For github.com/jpluimers/btrfs-du/blob/master/btrfs-du I wrote about last week, I also wanted that kind of behaviour. So I did some research and came up with the code and test cases below.
Note that depending on the bitness of your system, bash integer numeric values are limited in size; see [WayBack] What is the maximum value of a numeric bash shell variable? – Super User.
So I wrote a small bash script for that too, which needed also gave me the opportunity to show how a perpetual while loop as explained by [WayBack] bash – “while :” vs. “while true” – Stack Overflow.
Two things that always bite me with these short scripts are expressions (done through [WayBack]Arithmetic Expansion) and comparisons (through[WayBack] Other Comparison Operators).
The IEC suffixes contain one extra i to indicate binary and – next to the ISO notation that were already ISO defined – made it into the ISO 80000 standard since 2008. Here is a comparison list from [WayBack] Binary prefix – Wikipedia:
Prefixes for multiples of
bits (bit) or bytes (B) |
|
|
|
Most tools nowadays default to binary IEC suffixes for byte sizes, though disk manufacturers still use SI suffixes because, well then they appear bigger but aren’t. Just for comparison, look at the numbers from [WayBack] File size – Wikipedia and [WayBack] IEC and SI Size Notations – AN!Wiki where I got the test cases from:
Read the rest of this entry »
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2019/11/26
Hopefully I’ve been able to integrate some of the ideas in the links below in github.com/jpluimers/btrfs-du/blob/master/btrfs-du
One of the features I wanted there was to be able to add optional switches like --raw, --iec or --si to it similar to what as the btrfs qgroup show subcommand has.
It seems possible with bash, but it is not trivial, at least not for me as a non-frequent bash user, so here are some links to get me started:
In retrospect, other languages than bash might have been a better choice for a script like that (:
–jeroen
PS, some btrfs references:
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2019/11/20
One day, on a legacy Linux system, logrotate managed to skip some files in the middle of a sequence in /var/log.
Since I didn’t have time to sort out the cause (the system was being phased out), I used this to compress the rest of the log-files (dated in 2017):
sudo -u bash
pushd /var/log
ls | grep -vw xz | grep "\-20......$" | xargs -L 1 ls -alh
After that you can execute this in the same directory:
ls | grep -vw xz | grep "\-20......$" | xargs -L 1 time xz
It skips any xz files and includes only files in the year 2017.
I occasionally tracked progress with this:
ls -alh /var/log/ | grep -v xz | less
That got back a few gigabytes of disk space, just enough to help me migrate the system away.
–jeroen
Posted in *nix, *nix-tools, bash, logrotate, Power User | Leave a Comment »