Showing posts with label console. Show all posts
Showing posts with label console. Show all posts

This Week I Learned 2019 - Week 10

Last week post or something from the archive posts.

What else I've learned this week not within this post? Continue with the seventh week of ornamental fish culture learning. This week we looked into Zooplankton which consists of Artemia and Copepods; and Moina and Daphina. In addition, we also study artificial and processed feed as well as light intensity, water current, and exchange frequency. Related the paper we reviewed this week is on culturing techniques of Moina. And lastly, Mojo::Util is the Perl module of the week.

"道家弟子對佛像修練...成仙?成佛?"。那瞬间,我既然破功了,笑噴整整半个小时。天啊!《招摇》,这电视神剧居然还拍了整整55集!编剧们,你们幸苦了。可能我们已经有先入为主的看法吧,我们还是真真去看了一集后,结论是,其实不是难看,而是尴尬,不知如何再看下去了。


Should you still customize your GNU/Linux setup? (via HN). 22 years of usage and I still customize from time to time due to necessities or personal delicate preferences . As you get older, you're pretty much just stick to the default Desktop environment settings with some additional GNOME shell extensions. The only heavy customization is still at the console end, exactly like the author's post on customization.

To OO or not to OO in Perl? Is always better to OO as the system grows and it will. Otherwise you will end up with system done in PHP with a bunch of global functions.

What should we use to create textual UI in console? Dialog is the default available option and work with Bash. Off course there are libraries exists for different programming languages.

Finding and Deleting Files, xargs rm vs find -delete

Interesting comparison of finding and deleting files using both xargs and find command.

Create 10k files with 10 bytes each.
$ mkdir /tmp/test
$ dd if=/dev/zero of=masterfile bs=1 count=1000000
$ split -b 10 -a 10 masterfile

Using xargs.
$ time find -name 'xaa*' -print0 | xargs -0 rm
real    0m7.667s
user    0m1.112s
sys     0m6.491s

Using find with -delete option.
$ time find -name 'xaa*' -delete
real    0m7.252s
user    0m0.954s
sys     0m6.023s

Time difference of 0.415s, which is just insignificant. However, the -delete method way easier to remember.

Launch Default Web Browser From Console

Interesting, never realize there are so many ways. I should update my way of writing step-by-step guide.

1. sensible-browser
$ sinsible-browser http://google.com
$ man sensible-browser | grep DESCRIPTION -A 3
DESCRIPTION
sensible-editor, sensible-pager and sensible-browser make sensible decisions on which editor, pager, and web browser to call, respectively. Programs in Debian can use these scripts as their default editor, pager, or web browser or emulate their behavior.

2. xdg-open
$ xdg-open http://google.com
$ man xdg-open | grep DESCRIPTION -A 3
DESCRIPTION
xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.

3. x-www-browser
$ x-www-browser http://google.com
$ man x-www-browser
No manual entry for x-www-browser
See 'man 7 undocumented' for help when manual pages are not available.

$ ls -l `which x-www-browser`
lrwxrwxrwx 1 root root 31 Feb 22 21:08 /usr/bin/x-www-browser -> /etc/alternatives/x-www-browser

$ ls -l /etc/alternatives/x-www-browser
lrwxrwxrwx 1 root root 29 Feb 23 04:10 /etc/alternatives/x-www-browser -> /usr/bin/google-chrome-stable

No wonder, is Debian alternative system.
$ sudo update-alternatives --list x-www-browser
/usr/bin/google-chrome-stable
/usr/bin/iceweasel
/usr/bin/midori

4. gnome-open
$ gnome-open http://google.com
$ man gnome-open | grep DESCRIPTION -A 2
DESCRIPTION
This program opens files using file handlers configured in GNOME.

Explainshell

Via HN. Explainshell, a simple website to explain the parameters of the console program What a absolute fantastic helpful tool. One of those how come I never thought of that idea. Very useful when you're following a step-by-step tutorial and too lazy to search the meaning of each parameters through man page. Very useful if you need to learn console program with arcane command line arguments like iptables, GNU/Linux kernel firewall.

Sample example (shown below) of using iptables to set up Network Address Translation (NAT) . I used to cut and paste each description into one whole page to print out the full documentation to read it. Now is just too convenient with this tool.
iptables -t nat -A POSTROUTING -s 172.17.0.0/255.255.0.0 -o eth0 -j SNAT --to-source 212.170.21.172

Sending Email Through Console

$ echo "foobar" | mail -s "testing" [email protected]
The program 'mail' can be found in the following packages:
* heirloom-mailx
* mailutils
Try: apt-get install 

So, I was given two choices. Which one? I ended up picking mailutils because of dependency of Exim.
$ sudo -s
# sudo apt-get update; sudo apt-get upgrade;
# sudo apt-get install mailutils exim4-daemon-light
# dpkg-reconfigure exim4-config
- General type of mail configuration: internet site
- System mail name: foobar
- IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1
- Other destinations for which mail is accepted: foobar; localhost.localdomain; localhost
- Domains to relay mail for:
- Machines to relay mail for:
- Keep number of DNS-queries minimal (Dial-on-Demand) : 
- Delivery method for local mail: mbox format in /var/mail
- Split configuration into smaller files: 

To test.
$ exim -bt [email protected]

R: dnslookup for [email protected]
[email protected]
router = dnslookup, transport = remote_smtp
host mailinator.net [66.135.37.96] MX=10
$ echo "foobar" | mail -s "testing" [email protected]
$ sudo tail -f /var/log/exim4/mainlog

To use BCC or CC, you must install bsd-mailx package, the default GNU mailutils package does not support this.
$ sudo apt-get install bsd-mailx

Carbon Copy (CC).
$ echo "testing cc email" | mail -s "testing email cc" -c [email protected] [email protected]

Blind Carbon Copy (BCC).
$ echo "testing bcc email" | mail -s "testing email bcc" -b [email protected] [email protected]

Thanks to mailinator.com, you can check the email inbox at http://barfoo.mailinator.com and http://foobar.mailinator.com.

Send Email From Command Line

Occasionally during development, you'll need to send email to test out certain feature or cron job. Moreover, is nice to have this feature from the command line or console so you can debug and trace any issues.

$ echo "foobar" | mail -s "testing" [email protected]
The program 'mail' can be found in the following packages:
* heirloom-mailx
* mailutils
Try: apt-get install 

So, I was given two choices. Which one? I ended up picking GNU Mailutils because of dependency of Exim, which is known to be lightweight and easy to configure.
$ sudo -s
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install mailutils exim4-daemon-light
$ dpkg-reconfigure exim4-config

Exim mailer was configured using following settings.
  • General type of mail configuration: internet site
  • System mail name: foobar
  • IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1
  • Other destinations for which mail is accepted: foobar; localhost.localdomain; localhost
  • Domains to relay mail for:
  • Machines to relay mail for:
  • Keep number of DNS-queries minimal (Dial-on-Demand) : 
  • Delivery method for local mail: mbox format in /var/mail
  • Split configuration into smaller files: no

To check whether we've configure Exim correctly.
$ exim -bt [email protected]

R: dnslookup for [email protected]
[email protected]
router = dnslookup, transport = remote_smtp
host mailinator.net [66.135.37.96] MX=10

To send out a sample test email.
$ echo "foobar" | mail -s "testing" [email protected]
$ sudo tail -f /var/log/exim4/mainlog

However, GNU Mailutils does not support neither Bind Carbon Copy (BCC) nor Carbon Copy (CC). Hence, we've to install the bsd-mailx package.
$ sudo install apt-get install bsd-mailx

To send a Carbon Copy (CC) email.
$ echo "testing cc email" | mail -s "testing email cc" -c [email protected] [email protected]

To send a test Blind Carbon Copy (BCC) email.
$ echo "testing bcc email" | mail -s "testing email bcc" -b [email protected] [email protected]