Skip to main content

Posts

Showing posts from June, 2016

Linux Check IP Address or MAC Address

Linux good old command to check IP Address is  ifconfig which works probably in all distro. There is already new implementation on how to check the IP Address via command line from some distro. Some distro now supports the command, ip addr show which also displays the IP Address. The ifconfig command has a long output, which is quite scary if you are new to Linux. To filter the desired output in ifconfig, awk or gawk will come to the rescue. Below are some examples on how to do it: Display only the IP Address: ifconfig -a | awk 'NR==2' Sample Output: inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 Display only the MAC Address: ifconfig -a | awk 'NR==1' Sample Output: eth0  Link encap:Ethernet  HWaddr 07:00:16:f1:bb:ac HWaddr is the MAC Address Display both IP and MAC Address: ifconfig -a | awk 'NR==1,NR==2' Using awk command ifconfig output is displayed line by line. Some other useful command below to check users login

Shutdown or reboot computers with user abort option in Windows

Shutdown or reboot Windows client computer and let user decide to cancel or proceed with the system shutdown or reboot operation. Batch file script that can be deployed via GPO to shutdown or reboot client computers. Batch file can be set via Task Scheduler and run at a specified time. The script provides the user to cancel the operation, so if the user is in the midst of doing task that requires the system to be online then the user can choose to abort the operation. “IF /I” parameter on the script accepts "y" or "Y", it does case insensitivity comparison. If the input is not y or n, the batch file will keep asking until user presses the desired key. Here's the script: @ECHO OFF :xinvalid SET /P yes_or_no="Your computer will initiate shutdown in 10 min do you want continue (y/n): " IF /I %yes_or_no% EQU y ( SHUTDOWN /S /F /T 600 echo "Okay let’s do it, let’s shutdown the system."

Linux count string occurrences

How to use grep in Linux to count string occurrences? grep -oi "error" /home/xlog/xerrorlogs.txt    | wc -l Sample output: 5 (if there are 5 matches) Grep will look for the word "error" in xerrorlogs.txt and count its occurrence per line. Grep will find the string occurrence without case sensitivity. Grep parameters: -o --only-matching Print only the matched (non-empty) parts of matching lines, with each such part on a separate output line. -i --ignore-case Ignore case distinctions, so that characters that differ only in case match each other. wc - print newline, word, and byte counts for each file   -l, --lines               print the newline counts If "wc -l" is omitted: grep -oi "error" /home/xlog/xerrorlogs.txt    Grep will display the match string. Sample output: Error Error Error Error Error If Grep uses -c parameter: grep -oic "error" /home/xlog/xerrorlo

Word VBA Select Page

How to select a page in Word VBA? Sub Select_Home() 'Select the first page of the document (page 1) 'Like pressing Ctrl + Home Selection.GoTo wdGoToBookmark, , , "\StartOfDoc"                                                 End Sub Sub Select_document_end() 'Select the end of the document 'Like pressing "Ctrl+End" Selection.GoTo wdGoToBookmark, , , "\EndOfDoc"                                               End Sub Sub Select_via_Page_Number() 'specify the page number 'Example below will select page 5 Selection.GoTo wdGoToBookmark, , , "5" End Sub Tested and working using Word 2010. Cheers..till next time :) Happy coding. ================================ Free Android Apps: Click on links below to find out more: Linux Android App cheat sheet: https://play.google.com/store/apps/details?id=com.LinuxMobileKit https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer

Delete Directories with Wildcards using rd or rmdir

  Deleting files in command prompt using wildcards is quite straight forward. Command below will delete all text (".txt") files on the specified path.      Del D:\txtlog\*.txt Command above will delete all files with ".txt" extension in d:\txtlog directory. Easy enough to delete all matching files. Using the same method with rmdir or rd command this will not work. For example, if we have a directory on d drive that is auto-generated by an application and the filename is consistent with a pattern plus incrementing number at the end to differentiate the folder from other folders.    D:\baklogs\log1\    D:\baklogs\log2\    D:\baklogs\log3\    Etc..    D:\baklogs\log100\ The folder name has a consistent pattern that is preceded by the word “log” plus incrementing number. If the command below is executed to remove the directories in one go, an error is shown which has this message: "The filename, directory name, o

PowerShell get filename with extension

#======================================= $Folder_file_path="D:\test_folder\" $initCount=0 [array]$data_files = Get-ChildItem $Folder_file_path  #get all items and save to array   $i_count=$data_files.count  #count items on the array and assign to $i_count variable   Write-Host $initCount   #optional to display count value #if statement to process if files are found if($data_files.count -gt 0){ #increment for loop from zero to last index of the array  for  ($initCount; $initCount -lt $i_count; $initCount++ ) {         #Write-Host "$($data_files.Count) Files found in folder!"        Write-Host   ($data_files[$initCount].name ) #display the filename with the extension         Write-Output  ($data_files[$initCount].name ) >> d:\Files_list.txt # write data to a text file; ">>" append operator since for loop is used  } }else{     Write-Host No files in the folder! } #======================================= Change the script folder pat