Monday, January 8, 2018

Bash shell script to list Ethernet interfaces names and IPaddress on linux server.


If there are multiple IP addresses public, private, backup, etc are in use on linux server it takes a bit more of time to scroll down through the output of 'ifconfig' command and find the IP address assigned to it.

I have created a shell script nic.sh which list all the Ethernet interfaces and IP address assigned to them on Linux server.

#!/bin/bash

nic=$(ifconfig | cut -d" " -f1 | sed '/^$/d' | awk -vORS=',' '{ print $1}' | sed -e s/,$//g)

OFS=IFS
IFS=','
read -ra i <<< "$nic"
for i in "${i[@]}"; do
echo "$i ---> $(ifconfig | grep -A 1 -i $i | sed -n '2p' | awk -F" " '{ print $2 }' | cut -d":" -f2)"
done


root@localhost:/root>./nic.sh
eth0 ---> 192.168.1.19
lo ---> 127.0.0.1

Saturday, January 6, 2018

How to set a default tray for a printer in Linux?


When there are multiple trays available in the printer and we want the printer to pick papers from a specific tray we can use the below command.

Syntax:
# lpoptions -p <printer name> -o InputSlot=<TrayN>

Example:
# lpoptions -p billing -o InputSlot=Tray2

Here the printer billing will use Tray2 as the default tray.

You can check it to make sure if the printer billing is using the Tray2.
# lpoptions -p billing -l | grep  InputSlot
  InputSlot/Media Source: Auto Tray1 *Tray2 Tray3 Tray4

Note that the asterisk (*) in front of the Tray2.