Updated PowerShell script to loop through files for printing.

After finishing my script from the previous post I thought there has to be a better way to write this and reduce the lines of code. Not that 5 separate lines is a lot. But, if the list of items to print grew larger say to 15 documents, and was in different subdirectories then it might get complicated. So, I set about trying to find a way to use the ForEach-Object cmd. After some trial and error I have come up with this.
$Directory = “\\SVR1\DATA\Reports\Trading\”
Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 10;$_} | kill }
Read More

PowerShell comparison operators -eq, -lt, -gt, -contains, -like, -match

If you are used to operators such as > or < or =, you have to do some rethinking. As with batch scripts, PowerShell uses abbreviations of the corresponding English words. -eq Equal -ne Not equal -lt Less than -le Less than or equal -gt Greater than -ge Greater than or equal You don’t need an if statement to test the result of a comparison operation. Without the if statement, the output of the comparison is, simply, TRUE or FALSE. Read More

Test filters using fail2ban

Whenever you add or change a filter you will want to test that the regular expressions are correct by running it over an existing logfile.
The tool for doing this is fail2ban-regex which is used as follows:

fail2ban-regex /var/log/fail2ban.log /etc/fail2ban/filter.d/fail2ban-smtp.conf

Read More

How to set Java Home path [linux]

Set JAVA_HOME / PATH for a single user
Login to your account and open .bash_profile file
$ vi ~/.bash_profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java Read More

Postfix dkim and spf filtering

Installing OpenDKIM:
yum install opendkim
Create private and public key:

mkdir /etc/opendkim/keys/myhostname.lt
/usr/sbin/opendkim-genkey -D /etc/opendkim/keys/myhostname.lt/ -d myhostname.lt -s default
chown -R root:opendkim /etc/opendkim/keys/myhostname.lt
chmod 640 /etc/opendkim/keys/myhostname.lt/default.private
chmod 644 /etc/opendkim/keys/myhostname.lt/default.txt

Read More

Setting static IP in CentOS 7 Minimal Installation

In order to set the network adapter and get get CentOS to communicate on the network the Ethernet adapter will need to be configured. In this lesson I will set a static IP address for the network adapter. To view a list of your network adapters use the command ip addr.
The configuration file for the network adapter should be located at /etc/sysconfig/network-scripts/ifcfg-enp0s3. With the minimal installation of CentOS there are not many options available to configure the network adapter. One option is to use the vi editor or nano to configure ifcfg-enp0s3. Another option is to use the nmtui utility to edit the network adapter. Read More

Prevent DOS with iptables

Of course there are several types of DOS attacks , in this post I will demonstrating the use if iptables to limit the traffic on port 80.
The goal is to keep your web server “responsive” to legitimate traffic, but to throttle back on excessive (potential DOS) traffic.
In this demonstration iptables is configured :

  1. The default policy is ACCEPT (to prevent lockout in the event of flushing the rules with iptables -F).
  2. “Legitimate” traffic is then allowed. In this example I am allowing traffic only on port 80.
  3. All other traffic is then blocked at the end of the INPUT chain (the final rule in the INPUT chain is to DROP all traffic).

Read More

CentOS timezone config

CentOS timezone config files and directories

  • /usr/share/zoneinfo/ – The system timezone directory contains the files as per timezone name. For example, the file /usr/share/zoneinfo/America/New_York represents time zone for New York.
  • /etc/localtime – It is a symlink to the file localtime or to the correct timezone file in the system located in /usr/share/zoneinfo/ directory.

Read More