Send email with the date in the subject using mutt

Send yourself a copy of the network interfaces file within the body of the email, using mutt and including the current date automatically:

1
mutt -s "$(date) Network Interfaces File" user@example.com < /etc/network/interfaces

To send the same email, and attach the file:

1
echo "" | mutt -s "$(date) Network Interfaces File" -a /etc/network/interfaces -- user@example.com

The resulting email looks like:

———- Forwarded message ———-
From: root
Date: Wed, Jul 30, 2014 at 2:40 AM
Subject: Wed Jul 30 02:40:26 EDT 2014 Network Interfaces File

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

Command to determine speed of Network Interface Card (NIC)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
root@x61:~# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: off (auto)
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@compaq ~]# ethtool eth0
Settings for eth0:
 Supported ports: [ TP MII ]
 Supported link modes: 10baseT/Half 10baseT/Full
 100baseT/Half 100baseT/Full
 Supported pause frame use: No
 Supports auto-negotiation: Yes
 Advertised link modes: 10baseT/Half 10baseT/Full
 100baseT/Half 100baseT/Full
 Advertised pause frame use: No
 Advertised auto-negotiation: Yes
 Link partner advertised link modes: 10baseT/Half 10baseT/Full
 100baseT/Half 100baseT/Full
 Link partner advertised pause frame use: Symmetric
 Link partner advertised auto-negotiation: Yes
 Speed: 100Mb/s
 Duplex: Full
 Port: MII
 PHYAD: 32
 Transceiver: internal
 Auto-negotiation: on
 Supports Wake-on: pumbg
 Wake-on: d
 Current message level: 0x00000007 (7)
 drv probe link
 Link detected: yes

Mysql create user and database:

1
2
3
4
5
CREATE DATABASE db_name;
 
GRANT ALL PRIVILEGES ON db_name.* TO db_user @'localhost' IDENTIFIED BY 'db_passwd'; 
 
FLUSH PRIVILEGES;
This entry was posted on July 26, 2014, in Syntax and tagged .

Finding text in several files at the same time using Linux

http://cubicspot.blogspot.ca/2013/03/just-use-grep-dont-use-find-grep-xargs.html

 

Previously, I used to use:

1
find . | grep css| xargs grep "sidebar" -sl

 

This command works much better, faster and allows for the use of special characters in the search string.

1
grep -nir --include="*.php" "my_function" .

Here is sample output when running the following command:

1
root@t605:/etc# grep -nir --include="*" "10.10.0" .

 

grep_find_text

Start a service on boot Ubuntu

Here are the commands needed to set a service to start on boot.

Tested on Ubuntu Server 14.04 but should work just fine on older versions as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
root@t605:/# update-rc.d ntp enable
update-rc.d: warning:  start runlevel arguments (none) do not match ntp Default-Start values (2 3 4 5)
update-rc.d: warning:  stop runlevel arguments (none) do not match ntp Default-Stop values (1)
 Enabling system startup links for /etc/init.d/ntp ...
 Removing any system startup links for /etc/init.d/ntp ...
   /etc/rc1.d/K77ntp
   /etc/rc2.d/S23ntp
   /etc/rc3.d/S23ntp
   /etc/rc4.d/S23ntp
   /etc/rc5.d/S23ntp
 Adding system startup for /etc/init.d/ntp ...
   /etc/rc1.d/K77ntp -> ../init.d/ntp
   /etc/rc2.d/S23ntp -> ../init.d/ntp
   /etc/rc3.d/S23ntp -> ../init.d/ntp
   /etc/rc4.d/S23ntp -> ../init.d/ntp
   /etc/rc5.d/S23ntp -> ../init.d/ntp
 
 
usage: update-rc.d [-n] [-f] <basename> remove
       update-rc.d [-n] <basename> defaults [NN | SS KK]
       update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .
       update-rc.d [-n] <basename> disable|enable [S|2|3|4|5]
                -n: not really
                -f: force
 
The disable|enable API is not stable and might change in the future.

ncdu and its Awesomeness

Today I discovered ncdu while trying to find a script that would display all files on a Linux system sorted by size.

ncdu is Absolutely Amazing!

When you first run ncdu, it scans the current directory and any sub directories and calculates disk space used. It then sorts the output so you can easily find files that are the largest and taking up the most space.

Here is what it looks like when run under the /var/lib directory:

var-lib

 

Navigating further into /var/lib/libvirt/images shows the individual files sorted by size.

 

var-lib-libvirt-images

This entry was posted on July 22, 2014, in Linux and tagged .

List of software that should be installed on all Linux Systems:

  1. screen – for terminal multiplexing
  2. tmux – alternative terminal multiplexing
  3. weechat (if IRC is required)
  4. vim – my editor of choice
  5. ncdu – to display disk usage in a nice ncurses terminal
  6. openvpn – for all VPN needs
  7. x2go – remote desktop NX style
  8. xrdp – alternative remote desktop RDP style
  9. sar / sysstat – system performance monitoring tool

Verify NTP Status on Linux

1
2
3
4
5
6
7
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+name1.glorb.com 128.10.19.24     2 u  729 1024  377   64.538    3.350   1.540
+142.54.181.202  64.113.32.5      2 u   78 1024  377   46.030    2.374   1.829
*ntp.glorb.com   128.10.19.24     2 u 1003 1024  377   83.714   -2.968   1.872
-mailserv1.phoen LOCAL(0)         2 u  437 1024  377   13.746   -4.769   3.006

Display File System Types using df -T

1
2
3
4
5
6
7
8
9
10
root@x61:~# df -T
Filesystem               Type     1K-blocks     Used Available Use% Mounted on
/dev/mapper/x61--vg-root ext4     149399852 18707700 123079944  14% /
none                     tmpfs            4        0         4   0% /sys/fs/cgroup
udev                     devtmpfs   1975452        4   1975448   1% /dev
tmpfs                    tmpfs       397332     1216    396116   1% /run
none                     tmpfs         5120        0      5120   0% /run/lock
none                     tmpfs      1986644      144   1986500   1% /run/shm
none                     tmpfs       102400       28    102372   1% /run/user
/dev/sda1                ext2        240972    36912    191619  17% /boot
This entry was posted on July 22, 2014, in Linux and tagged , .