:::: MENU ::::

Home

  • Jun 14 / 2017
  • 0
Linux

Change ownership (chown) on a symbolic link

You already probably noticed that if you want to update the ownership of a symbolic link on any UNIX system, a simple chown won’t do the job.

Indeed, let’s suppose you have this:

8 lrwxr-xr-x   1 user1            group1         4 Jun 13 23:46 link -> test 
8 -rw-r--r--   1 user1            group1         6 Jun 13 23:54 test

If you’re doing a simple chown:

chown user2:group2 link

You can see that it changes the ownership on the target file and not on the symbolic link:

8 lrwxr-xr-x   1 user1            group1         4 Jun 13 23:46 link -> test 
8 -rw-r--r--   1 user2            group2         6 Jun 13 23:54 test

If you want to update the symbolic link, you need to use the -h or –no-dereference option to apply the changes on the symbolic link and not on the target:

chown -h user2:group2 link

Then, you can see that it’s now updated:

8 lrwxr-xr-x   1 user2            group2         4 Jun 13 23:46 link -> test 
8 -rw-r--r--   1 user2            group2         6 Jun 13 23:54 test
  • May 30 / 2017
  • 0
Linux, Python

DNS queries from a file/list to CSV

It’s not easy to perform bulk DNS resolution when you have many DNS/IPs to control. Here is a simple script allowing you to perform DNS resolution over a list of DNS entries or IPs.

Here is a list of DNS (names and IPs) that we put in a file called listDNS.txt

www.python.org
www.pyython.org
208.67.220.220
www.bing.com

Let’s copy that script that will do the job in a file called resolverDNS.sh

#!/bin/bash
# Script file - resolverDNS.sh
# Checking existence of arg
if [ "$1" == "" ]
then
  # Display help if wrong usage
  echo "Usage: /bin/bash resolverDNS.sh /path/to/file"
  exit 35
else 
  # Loop over dns and resolve
  while IFS='' read -r line || [[ -n "$line" ]]; do
    dns=''
    # Resolve reverse DNS
    if [[ $line =~ ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
      dns=`dig +noall +answer -x $line +short|tr 'n' ' '`
    # Resolve A record
    else
      dns=`dig a $line +short|tr 'n' ' '`
    fi
    echo -e "$linetis resolving intot${dns}"
  done < "$1"
fi

And now, execute it by passing file path as an arg, and see the output:

$ bash /home/user/resolverDNS.sh /home/user/listDNS.txt 
www.python.org	is resolving into	python.map.fastly.net. 151.101.60.223 
www.pyython.org	is resolving into	
208.67.220.220	is resolving into	resolver2.opendns.com. 
www.bing.com	is resolving into	www-bing-com.a-0001.a-msedge.net. a-0001.a-msedge.net. 204.79.197.200 13.107.21.200 

Resolution are done for every line, depending on if it’s an IP or a name (and remain empty if it can’t resolve).
Feel free to adjust the script according to your needs!

  • 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 🙂 !

Pages:12345678...18
Question ? Contact