UpFront

The UpFront Section

UpFront

Tech Tip

In a previous tech tip, we saw how to use kill to monitor processes. Another option is to use ps. With both methods, you can check $? for success/failure. However, note that kill -0 may return failure even if the process actually exists. This happens when the current user has no permission to the process in question, for example: kill -0 1.

To check for a process silently (with no output), use:

kill -0 PID 2>/dev/null
ps -p PID >/dev/null

Tech Tip

When looking at log files or other files that are compressed and rotated automatically, it's useful to be able to deal with them in a uniform fashion. The following bash function does that:

function data_source ()
{
 local F=$1

 # strip the gz if it's there
 F=$(echo $F | perl -pe 's/.gz$//')

 if [[ -f $F ]] ; then
  cat $F
 elif [[ -f $F.gz ]] ; then
  nice gunzip -c $F
 fi
}

Now, when you want to process the files, you can use:

for file in * ; do
 data_source $file | ...
done

If you have bzip2 files, just modify the data_source function to check for that also.

Tech Tip

Using netstat, you can monitor programs that are making connections to remote hosts:

$ netstat -tpe

The -t flag limits the output to show only TCP connections. The -p flag displays the PID and name of the program making the connection. The -e flag displays extra information, such as the user name under which each program is running.

______________________

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix