Ahoy there! This is my personal blog which I use as my memory extension and a medium to share stuff that could be useful to others.

Under normal working conditions, when SNMP Managers query SNMP agents (snmpd) on RHEL 6, several lines of information similar to the following are logged into syslog:

 May 27 17:39:14 MyLinuxHost snmpd[1521]: Connection from UDP: [192.168.100.200]:54907->[172.23.10.10] 

As snmpd is typically queried frequently, your syslog (e.g. /var/log/messages) will be filled with several such informational lines as this can lead to “noise” and is truly not required.

SNMP Logging Levels are given below:

LOG LEVEL DESCRIPTION
0 Emergencies – System is unusable
1 Alerts – Immediate action needed
2 Critical – Critical conditions
3 Errors – Error conditions
4 Warnings – Warning conditions
5 Notifications – Informational messages
6 Informational – Normal but significant conditions
7 Debugging – Debugging messages

By default, SNMP on RHEL 6 has logging levels 0-6 enabled. The redundant information in the logs is logged at level 6. Given below are steps to disable these informational messages for SNMP on RHEL 6:

STEP 1:Modify the SNMP Logging Level

Edit /etc/init.d/snmpd and modify the OPTIONS variable to reflect logging levels 0-5 as shown below:

 OPTIONS="-LS0-5d -Lf /dev/null -p /var/run/snmpd.pid" 

STEP 2:Restart the SNMP service

Restart the SNMP service for the changes to take effect:

 sudo service snmpd restart 
VN:F [1.9.22_1171]
Rating: +17 (from 23 votes)

Given below are some tips from my scratchpad on working with files and directories in PowerShell. These are just basic tips and by no means exhaustive. Check out the book “Windows PowerShell in Action” by Bruce Payette, an excellent book on PowerShell authored by the lead developer of the language.

# Directory Listing
PS C:\POWERSHELL> dir


    Directory: C:\POWERSHELL


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        12/29/2010  12:01 PM       1929 PowerShellTips.ps1
-a---        12/29/2010  10:40 AM         50 test1.txt

# Number of files in a directory
PS C:\POWERSHELL> (dir).count
3
PS C:\POWERSHELL> (dir).length
3
# Number of files matching a pattern
PS C:\POWERSHELL> (dir *.ps1).count 
1

# Number of lines in a file
PS C:\POWERSHELL> ${C:PowerShellTips.ps1}.length
141
PS C:\POWERSHELL> (Get-Content .\PowerShellTips.ps1).length
141
PS C:\POWERSHELL> (Get-Content .\PowerShellTips.ps1).count
141

# Largest file in a directory
PS C:\POWERSHELL> dir | Sort-Object -property length -Descending | Select-Object -first 1 | foreach-object {$_.length}
7157724

# Files created in the last 31 days
PS C:\POWERSHELL> dir | ?{$_.lastwritetime -ge ([datetime]::Now).AddDays(-31)} | %{"I am " + $_.Name}
I am PowerShellTips.ps1
I am test1.txt

PS C:\POWERSHELL> dir | %{if ($_.lastwritetime -ge ([datetime]::Now).AddDays(-31)) {"I am " + $_.Name}}
I am PowerShellTips.ps1
I am test1.txt
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Given below are useful tips on PowerShell DateTime operations (from my 2010 scratchpad):

# Get Formatted DateTime
PS C:\> Get-Date -Format "dd/MM/yyyy"
28/12/2010

PS C:\> $(Get-Date -Format "yyyyMMddHHmmss") + ".log"
20101228064357.log

# Time till New Year
PS C:\> $now = [datetime]::Now
PS C:\> [datetime] ([string] ($now.Year+1) + "-01-01") - $now


Days              : 3
Hours             : 17
Minutes           : 14
Seconds           : 28
Milliseconds      : 970
Ticks             : 3212689708670
TotalDays         : 3.7183908665162
TotalHours        : 89.2413807963889
TotalMinutes      : 5354.48284778333
TotalSeconds      : 321268.970867
TotalMilliseconds : 321268970.867

# Days between dates
PS C:\> [string] $([datetime] "01/26/2010" - [datetime] "01/01/2010").Days + " Days"
25 Days

# DateTime Comparison
PS C:\> [datetime]::Compare([datetime] "01/01/10", [datetime] "01/01/11")
-1
PS C:\> [datetime]::Compare([datetime] "01/01/10", [datetime] "01/01/09")
1
PS C:\> [datetime]::Compare([datetime] "01/01/10", [datetime] "01/01/10")
0
PS C:\> [datetime]::Compare([datetime] "01/01/10 20:00", [datetime] "01/01/10 19:00")
1

# Add and Subtract Time
PS C:\> [datetime]::now

December-28-10 11:01:17 AM


PS C:\> ([datetime]::now).AddHours(1)

December-28-10 12:01:37 PM


PS C:\> ([datetime]::now).AddHours(-1)

December-28-10 10:01:42 AM
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Given below are three methods (there could be more) of determining your Hostname in PowerShell:

METHOD 1:

# Fastest method
PS C:\> $env:COMPUTERNAME

METHOD 2:

# Slowest method
PS C:\> $(Invoke-Expression hostname)

METHOD 3:

PS C:\> [System.Net.Dns]::GetHostName()

VN:F [1.9.22_1171]
Rating: +6 (from 6 votes)

One method of determining your PowerShell version is to check the Windows Registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine. Given below are other(recommended) methods of obtaining version information for your PowerShell:

PS C:\POWERSHELL> $PSversiontable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.3053
BuildVersion                   6.0.6002.18111
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1


PS C:\POWERSHELL> $PSversiontable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

PS C:\POWERSHELL> [string]$PSVersionTable.PSVersion.Major+"."+$PSVersionTable.PSVersion.Minor
2.0

VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
 Page 5 of 33  « First  ... « 3  4  5  6  7 » ...  Last »