Middleware was fourth hottest skills to get hired in 2017, and there is no reason to go down in coming years.
If you recently started working on WebSphere or any other product suite of Middleware, then one of the very first things to get familiar is widely used Linux commands.
In this article, I will talk about some of the often-used Linux commands by WebSphere or Middleware administrator on a daily basis.
If you are working on existing environment and if an administrator has redirected SystemOut.log to some other location then it would be challenging to find it.
#find / -name SystemOut.log
Tips: if you have multiple file system then it may take time to search. So best would be to replace / with actual file system where you think the log would be. Let’s say you believe log is in /opt file system so you can do like this.
#find /opt –name SystemOut.log
Know which process is holding specific port number
Quite often you will have to deal with port conflict issue, especially in the shared environment.
If there is a situation to find out which process is holding port number then here is how you can know.
#netstat –anlp | grep 443
[[email protected] ~]# netstat -anlp | grep 443 tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 20924/nginx [[email protected] ~]#
Note: Above example shows nginx with PID 20924 is holding 443 port.
Server boot time
If you are performing auto-startup troubleshooting and would like to know when the server was rebooted, you can use this command.
[[email protected] ~]# who -b system boot Jun 28 01:11 [[email protected] ~]#
who -b command will give you exact date and time of server reboot.
Alternatively, you may also use up time to check how long the server is up.
[[email protected] ~]# uptime 01:20:27 up 14 days, 9 min, 1 user, load average: 0.00, 0.00, 0.00 [[email protected] ~]#
Check CPU/Memory utilization in runtime
If you are having a performance issue, then you might want to know the current CPU/Memory utilization.
This will help you to find out which process is taking high CPU/Memory in real-time.
#top top - 01:16:21 up 14 days, 5 min, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st Mem: 502220k total, 454920k used, 47300k free, 143476k buffers Swap: 0k total, 0k used, 0k free, 245412k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 29121 root 20 0 15008 1260 992 R 0.3 0.3 0:00.02 top 1 root 20 0 19232 1136 860 S 0.0 0.2 0:25.18 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:01.21 ksoftirqd/0
Tips: look for CPU/Memory section for first few PID to find out the utilization.
Alternatively, you may also use free command to find out total and free memory.
[[email protected] ~]# free -m total used free shared buffers cached Mem: 490 444 46 0 140 239 -/+ buffers/cache: 64 425 Swap: 0 0 0 [[email protected] ~]#
As you can see above, there is 490 MB total memory, and only 46 MB memory is available.
There is another command called SAR (System Activity Report), which is also very helpful to find the CPU and Memory stats.
To check the CPU utilization
To check the Memory utilization
Kill the process
The sometimes process doesn’t stop gracefully if it’s hung or defunct. In this scenario, you can kill the process manually.
If above doesn’t help, you can use -9 to kill the process forcefully.
#kill -9 PID
Note: PID is your process ID
Compression & Extraction
Most often you will have to deal with compressing the files as housekeeping activity for a file system.
gzip command can be used to compress the files.
Tips: if you have multiple files to be compressed, you can use gzip * which will compress all the files available in that working directory.
gunzip command will help you to extract the gz file.
Tips: you can use gunzip * which will help you to extract all gz file in that working directory.
Total CPU, Memory, File System
Often asked to provide server information, if you are working on migration or capacity planning.
Here is the quick command to help you to find out total CPU, Memory, and File system details.
Find out CPU Cores, MHz, CPU manufacturer, Model Name and much more by using
Tips: if you have a high-end server then an output of above command will be long. So you can use grep to filter out the required information. For ex, just to find out cores, you can use
#cat /proc/cpuinfo | grep cores
To find out total available memory, you can use one of the following commands.
This will show you total, free & cached memory
This will show you much more information along with total memory.
File System information
To find out file system size and usage, you can use df commands.
[[email protected] tmp]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 20G 1.6G 18G 9% / tmpfs 246M 0 246M 0% /dev/shm [[email protected] tmp]#
Including –h will give you output in GB which is easy to understand.
Check out IP, Subnet Mask, MAC address and errors
Probably, one of the most widely used commands to find out IP related information.
[[email protected] tmp]# ifconfig eth0 Link encap:Ethernet HWaddr 04:01:5A:25:57:01 inet addr:188.8.131.52 Bcast:184.108.40.206 Mask:255.255.192.0 inet6 addr: fe80::601:5aff:fe25:5701/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1491330 errors:0 dropped:0 overruns:0 frame:0 TX packets:1636419 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:306418374 (292.2 MiB) TX bytes:274350737 (261.6 MiB) [[email protected] tmp]#
As you can see above, ifconfig will show the IP addresses, Ethernet details, a hardware address (MAC), subnet mask, errors and other information. This is the extremely useful handy command if you are looking for this information.
Tips: you can use –a with ifconfig to show all available Ethernet details. Ex:
Network commands like wget, telnet, traceroute
If you are doing application connectivity troubleshooting then most likely you will need to use these network commands.
Check if you can access particular URL from server
You can quickly confirm if there is any connectivity issue on your server by using wget command. Ex: if you need to check if the server can access external website like https://geekflare.com or not, you can use below.
[[email protected] tmp]# wget geekflare.com --2015-07-12 02:52:56-- https://geekflare.com/ Resolving geekflare.com... 220.127.116.11, 18.104.22.168 Connecting to geekflare.com|22.214.171.124|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: `index.html' [ <=> ] 65,435 --.-K/s in 0.005s 2015-07-12 02:52:56 (13.4 MB/s) - `index.html' saved  [[email protected] tmp]#
Tips: above you can see HTTP response code is 200 means there is no issue in connectivity.
Verify if server can connect to backend service with particular port number
If you are connecting to some other application like web service and need to verify if you can reach them, then you can use telnet command. This is very useful for connectivity test.
In below example, I have checked if geekflare.com on 443 port can be reached or not.
[[email protected] tmp]# telnet geekflare.com 443 Trying 126.96.36.199... Connected to geekflare.com. Escape character is '^]'.
If you see “Connected” then that confirms there is nothing wrong with connectivity/firewall. However, if you see connection failed then you know, there is something like a firewall blocking your connection.
Tracing connection details
This may not be used all the times but extremely helpful when you have latency issue or just want to find out the connection path between your server to the destination.
Below example is to show the network path from my server to geekflare.com
[[email protected] tmp]# traceroute geekflare.com traceroute to geekflare.com (188.8.131.52), 30 hops max, 60 byte packets 1 184.108.40.206 (220.127.116.11) 5.110 ms 5.061 ms 18.104.22.168 (22.214.171.124) 0.418 ms 2 126.96.36.199 (188.8.131.52) 5.153 ms 0.463 ms 184.108.40.206 (220.127.116.11) 8.009 ms 3 as13335.singapore.megaport.com (18.104.22.168) 4.822 ms 13335.sgw.equinix.com (22.214.171.124) 4.819 ms as13335.singapore.megaport.com (126.96.36.199) 4.490 ms 4 188.8.131.52 (184.108.40.206) 4.454 ms 4.427 ms 4.366 ms [[email protected] tmp]#
If you are dealing with multiple users on a server and having root permission too then most likely once in a while, you will screw with permission/ownership. Well, not to worry its part of learning.
Here is the quick way to change the ownership or permission.
To change ownership of a particular file, you can use the chown command as below.
#chown user:group error.log
Tips: above will change ownership of error.log to mentioned user and group. If you have a folder, then you can use –R, which will change recursively to all the files within the folder. Ex:-
#chown –R user:group somefolder
I hope above commands will help you to speed up your working style on Linux environment.