:::: MENU ::::

Posts Categorized / Linux

  • May 15 / 2017
  • 0
Linux

Remove list of mail addresses from postfix queue

There is no easy way to remove a list of mails in queue with a same sender or domain in Postfix. But you can use some standard commands to get this working.

First check the list of mails you want to remove with something like

postqueue -p |grep -e '[email protected]|[email protected]|[email protected]' -B2 |grep "^[A-Z0-9]"

You’re getting the list of mails that you will remove with the sender

FC0177DF1A0     8373 Thu May  6 11:24:56  [email protected]
F179A2C68AB     9469 Sun May  7 03:21:41  [email protected]
EAE217FB850    11049 Sat May  8 04:20:32  [email protected]

And now you can remove those mails from the queue by using postsuper -d

postqueue -p |grep -e '[email protected]|[email protected]|[email protected]' -B2 |grep "^[A-Z0-9]{10}" |cut -d" " -f1 |postsuper -d -

You will see the mails being removed

postsuper: FC0177DF1A0: removed
postsuper: F179A2C68AB: removed
postsuper: EAE217FB850: removed
postsuper: Deleted: 3 messages
  • May 04 / 2017
  • 0
Linux

Reduce partition size on EXT filesystems on Linux

It is possible to modify a partition size on EXT filesystem thanks to some few commands.

We will take here a simple example:

  • We have a /dev/sda5 partition mounted on /home
  • Its size is currently 150G and we want to reduce it to 100G

Let’s check the current config (mounting point and size):

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        28G  3.3G   23G   8% /
/dev/sda2       477M  112M  341M  25% /boot
/dev/sda3       4.7G   12M  4.5G   1% /tmp
/dev/sda4        32G  470M   30G   2% /var
/dev/sda5       148G   87M  140G   1% /home

We need to first unmount the partition:

# umount /dev/sda5

If you can’t unmount it, double check what process is using it with the lsof command:

# lsof /home

Then proceed with a check with e2fsck command and resize the partition with resize2fs by defining the new size (M for Megabytes, G for Gigabytes, and so on…)

# e2fsck -f /dev/sda5
# resize2fs /dev/sda5 100G

Mount your partition back to your system:

# mount /home

And check again your partition sizes :

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        28G  3.3G   23G   8% /
/dev/sda2       477M  112M  341M  25% /boot
/dev/sda3       4.7G   12M  4.5G   1% /tmp
/dev/sda4        32G  470M   30G   2% /var
/dev/sda5        99G   87M   94G   1% /home

We can see that the partition /home has now a size of 100G as expected!

  • Apr 24 / 2017
  • 0
Linux

Find ILO IP on a HP server with Linux

If you forgot what iLO IP has been defined on your linux server and you are working remotely on it, don’t worry, you can still retrieve it with a common tool called ipmitool – available on most of the distros with standard packages:

[[email protected] /]# ipmitool lan print
Set in Progress : Set Complete
Auth Type Support :
Auth Type Enable : Callback :
: User :
: Operator :
: Admin :
: OEM :
IP Address Source : Static Address
IP Address : 10.10.50.20
Subnet Mask : 255.255.255.0
MAC Address : 1a:2b:3c:4d:56:78
SNMP Community String :
BMC ARP Control : ARP Responses Enabled, Gratuitous ARP Disabled
Default Gateway IP : 10.10.50.254
802.1q VLAN ID : Disabled
802.1q VLAN Priority : 0
RMCP+ Cipher Suites : 0,1,2,3
Cipher Suite Priv Max : XuuaXXXXXXXXXXX
: X=Cipher Suite Unused
: c=CALLBACK
: u=USER
: o=OPERATOR
: a=ADMIN
: O=OEM

If you’re getting such an error when you are using the command:

[[email protected] /]# ipmitool lan print
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory

This means you just need to enable some modules before:

[[email protected] /]# modprobe ipmi_devintf
[[email protected] /]# modprobe ipmi_si
  • Apr 13 / 2017
  • 0
Linux

Quit telnet – Escape character

Stuck with a telnet session that refuses to give you hand back on console?
No worries… You just have to know the correct command to sort this out!

When you are opening a telnet connection, you probably got something like:

[email protected]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

So, if you want to quit, you just have to use the “escape character” as indicated. But this character is not designed to be typed with 2 characters like “^” and then “]” – you have to use a direct command that can be different depending on your OS:

  • Windows: Ctrl + $
  • Linux: Ctrl + Alt Gr + ]
  • Mac OS: Ctrl + $

And press Enter once you inserted this escape character so you can get the standard telnet prompt and be able to type quit to exit the prompt.

This will result in a command like:

^]
telnet> quit
Connection closed.
[email protected]#

And here you go – you’re out of telnet 🙂 !

  • Apr 07 / 2017
  • 0
Linux

Display time with history command

When you are using the history command on a UNIX system, by default, you’re only getting an action list with numbers but no date and/or time to complete this history. For that, you have to define an environment variable HISTTIMEFORMAT that will describe how you want to display the timestamp for each command.

To display the timestamp temporarily (during session), you can just export the variable before sending the command:

$export HISTTIMEFORMAT="%d/%m/%y %T " ; history

You will get:

2021  01/04/17 11:54:04 systemctl list-units
2022  01/04/17 11:54:10 systemctl list-unit-files
2023  01/04/17 11:54:15 cd /etc/
2024  01/04/17 11:54:33 ls -lsta
2025  01/04/17 11:54:33 ps auxw | grep apache
2026  01/04/17 11:54:35 date
2027  01/04/17 11:54:35 cd ..
2028  01/04/17 11:54:37 cd /var/log
2029  01/04/17 11:54:37 ls -lsta
2030  01/04/17 11:54:40 cat messages
2031  01/04/17 15:48:44 history
2032  01/04/17 15:48:51 export HISTTIMEFORMAT="%d/%m/%y %T " ; history

If you want to keep that display for a future session, you have to add this variable to your bash profile and reload your profile:

$echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
$source ~/.bash_profile
  • Mar 24 / 2017
  • 0
Linux

Create multiple symlink by changing name with command find

Let’s imagine that we have the following directory listing:

$ ls -ls /data/db1/
total 4778688
   1488 -rw-r--r-- 1 dbmaster      760264 Feb 14 00:20 database_2016_file1
    496 -rw-r--r-- 1 dbmaster      251529 Dec 29 12:45 database_2016_file2
 808960 -rw-r--r-- 1 dbmaster   414187520 Jan 30 10:20 database_2016_file3
    344 -rw-r--r-- 1 dbmaster      172544 Mar 18 00:42 database_2016_file4
 958528 -rw-r--r-- 1 dbmaster   490764886 Feb  7 12:18 database_2016_file5
  19480 -rw-r--r-- 1 dbmaster     9970189 Mar  2 17:31 database_2016_file6
2813952 -rw-r--r-- 1 dbmaster  1440743424 Mar 20 10:00 database_2016_file7
 160336 -rw-r--r-- 1 dbmaster    82088969 Mar 22 10:30 database_2016_file8
  14632 -rw-r--r-- 1 dbmaster     7490048 Mar 16 16:13 database_2016_file9
    104 -rw-r--r-- 1 dbmaster       51525 Mar  2 16:18 database_2016_idx1
     32 -rw-r--r-- 1 dbmaster       16114 Dec 14 18:55 database_2016_idx2
    144 -rw-r--r-- 1 dbmaster       71056 Dec  6 13:32 database_2016_idx3
     40 -rw-r--r-- 1 dbmaster       18214 Mar  9 12:38 database_2016_idx4
    104 -rw-r--r-- 1 dbmaster        8686 Jan  5 09:10 database_2016_idx5
     48 -rw-r--r-- 1 dbmaster       21316 Dec 14 20:01 database_2016_idx6

We would like to get a copy of those files named 2016 with a new name for the 2017 year, but we need to keep same content and retro-compatibility. For that, it’s easier to create some symbolic links of all those files instead of doing copies.

You can so use this command for creating those symlinks:

find /data/db1/ -type f -name "database_2016*" -exec bash -c 'ln -s $1 ${1/2016/2017}' -- {} ;

We are now getting this, as expected:

$ ls -ls /data/db1/
total 4778808
   1488 -rw-r--r-- 1 dbmaster      760264 Feb 14 00:20 database_2016_file1
    496 -rw-r--r-- 1 dbmaster      251529 Dec 29 12:45 database_2016_file2
 808960 -rw-r--r-- 1 dbmaster   414187520 Jan 30 10:20 database_2016_file3
    344 -rw-r--r-- 1 dbmaster      172544 Mar 18 00:42 database_2016_file4
 958528 -rw-r--r-- 1 dbmaster   490764886 Feb  7 12:18 database_2016_file5
  19480 -rw-r--r-- 1 dbmaster     9970189 Mar  2 17:31 database_2016_file6
2813952 -rw-r--r-- 1 dbmaster  1440743424 Mar 20 10:00 database_2016_file7
 160336 -rw-r--r-- 1 dbmaster    82088969 Mar 22 10:30 database_2016_file8
  14632 -rw-r--r-- 1 dbmaster     7490048 Mar 16 16:13 database_2016_file9
    104 -rw-r--r-- 1 dbmaster       51525 Mar  2 16:18 database_2016_idx1
     32 -rw-r--r-- 1 dbmaster       16114 Dec 14 18:55 database_2016_idx2
    144 -rw-r--r-- 1 dbmaster       71056 Dec  6 13:32 database_2016_idx3
     40 -rw-r--r-- 1 dbmaster       18214 Mar  9 12:38 database_2016_idx4
    104 -rw-r--r-- 1 dbmaster        8686 Jan  5 09:10 database_2016_idx5
     48 -rw-r--r-- 1 dbmaster       21316 Dec 14 20:01 database_2016_idx6
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file1 -> /data/db1/database_2016_file1
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file2 -> /data/db1/database_2016_file2
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file3 -> /data/db1/database_2016_file3
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file4 -> /data/db1/database_2016_file4
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file5 -> /data/db1/database_2016_file5
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file6 -> /data/db1/database_2016_file6
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file7 -> /data/db1/database_2016_file7
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file8 -> /data/db1/database_2016_file8
      8 lrwxr-xr-x 1 dbmaster          30 Mar 24 13:59 database_2017_file9 -> /data/db1/database_2016_file9
      8 lrwxr-xr-x 1 dbmaster          29 Mar 24 13:59 database_2017_idx1 -> /data/db1/database_2016_idx1
      8 lrwxr-xr-x 1 dbmaster          29 Mar 24 13:59 database_2017_idx2 -> /data/db1/database_2016_idx2
      8 lrwxr-xr-x 1 dbmaster          29 Mar 24 13:59 database_2017_idx3 -> /data/db1/database_2016_idx3
      8 lrwxr-xr-x 1 dbmaster          29 Mar 24 13:59 database_2017_idx4 -> /data/db1/database_2016_idx4
      8 lrwxr-xr-x 1 dbmaster          29 Mar 24 13:59 database_2017_idx5 -> /data/db1/database_2016_idx5
      8 lrwxr-xr-x 1 dbmaster          29 Mar 24 13:59 database_2017_idx6 -> /data/db1/database_2016_idx6
Pages:12345678...14
Question ? Contact