Posts

Showing posts with the label Script

List completed cron jobs in Centos

Listing cron jobs or log files within a specific time frame is quite hard especially if the log or logs are quite a big file.

But of course, doing the lazy way but a smarter way is always a good option.

Use SED or stream editor.

In Centos the log is in: /var/log/cron

/var/log - path for the file
 cron - is the file that keeps the record for cron jobs, there is no filename extension

To check the logs within the 24 hours time, sed can do it easily and quickly.

Here's one line, time saver command to check the cron log file:

sed -n '/Mar 10 00:00:01/ , /Mar 11 00:01:01/p' /var/log/cron

To redirect the output to a file:

sed -n '/Apr 10 00:00:01/ , /Apr 11 00:01:01/p' /var/log/cron > cron24_hours.record.log

You can replace /var/log/cron with any other files as long as it follows the time format of Month, Day of the month and the time in HR:MM:SS format.


Download the free Linux Android App cheat sheet, see link below. It's free. Enjoy.



Cheers..till next time!

=======…

Domain Computer takes a long time to login

Login process should be quick and fast, so every user will be happy and start the day smoothly.
But not every day is a new year’s day and there are times that things will just go south and some issues will surface.
Enabling verbose login in local group policy will definitely help to troubleshoot which part of the login process the system halts and takes a long time to process.
Folder redirection for some reason will cause an issue that will take time to load the desktop or causes a login issue.
There are quite a lot of reasons why a GPO takes time to process, and causes login issue.
But if a computer or workstation has been working fine and all of a sudden gives a logon issue; no changes has been made on the server or GPO. Then an issue could occur at the workstation or client side.
One solution that might work on this kind of scenario is to open an elevated command prompt and issue this command on the problematic user computer:
Netsh winsock reset

Normally, the command above is issue…

PowerShell copy file, link or folder to users’ desktop

Deploying a shortcut link, file or folders can easily be done via group policy preferences.
Or it can also be done using PowerShell as logon or start up script.
A one liner code snippet to deploy a file, a shortcut links or a folder to user’s desktop.
Copy a file: copy-item "\\shared_folder\files_2be_copied.txt" "c:\users\public\desktop"
Copy a shortcut link to user desktop: copy-item "\\shared_folder\shortcut_file_2be_copied.lnk" "c:\users\public\desktop"
Copy a folder: copy-item "\\shared_folder\folder_2be_copied" "c:\users\public\desktop" -Container -Recurse


================================ 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
Multiplication Table for early learnershttps://play.google.com/store/apps/details?id=com.TableMultiplication
Catholic Rosary Guide  for Android:
https://play.google.com/store/apps/details?id=com.my…

PowerShell move matching files in a folder

Requires PS 3.0
This is a two lines code snippet to move matching files in a source folder to another folder.
#==============================

$SourceFolder = "C:\File_monitor_records\"
# Find all files matching *.csv in the folder specified  # Find csv files with 2016 in its filename Get-ChildItem -Path $SourceFolder -Filter *2016*.csv | move-item  -destination C:\File_monitor_archives\2016\

#==============================
-Filter *2016*.csv –adjust or create your own pattern, use regex if necessary
Test the pattern before moving the files to make sure correct files are being moved. Check and double check, to avoid wasting time and effort.
This will just like matching files.

Get-ChildItem -Path $SourceFolder -Filter *2016*.csv


Move files and change file name:
http://quickbytesstuff.blogspot.sg/2015/06/powershell-move-files-and-change-file.html

================================ Free Android Apps:
Click on links below to find out more:
Linux Android App cheat sheet: https://play.google.com/s…

Windows audio disabled and wireless icon showing disconnected

In Windows 7 I encountered an issue showing that “Windows Audio is disabled”, I had checked the device manager audio devices was working fine. I checked the Windows Audio Volume Control, the default speaker is enabled. I checked the “Audio disabled devices”, there was a device that was disabled but cannot enable.

I tried restarting Windows Audio Service but it just doesn’t help. I did some Googling and one of the results points to Microsoft Online Answers Community and one respondent suggested the commands below:

Run commands below at an elevated mode or Administrator mode.

net localgroup Administrators /add networkservice press enter then type:

net localgroup Administrators /add localservice press enter and restart your computer

Link to the original article:
https://answers.microsoft.com/en-us/windows/forum/windows_7-pictures/audio-device-is-disabled/3d49e32d-6c1c-44c8-a7b3-52166a0233b0

After restarting the computer, the audio was working already.

Aside from the Windows Audio is di…

VB.Net remove line feed or new line

In VB.net or any programming language, if the program requires getting data from external programs, results or data from third party software that needs to be processed  may or may not have expected desired output.

For example, getting a string from a third party software. String is quite straight forward and it's quite basic.

But the issue arises,  if the desired output requires a specific string or text and other text should be discarded or deleted. Regex or any other methods might help on getting the specific text or data.

One basic issue, if the string needs to be formatted in one line but a line feed or a new line keeps breaking the line.

The first instinct that I think of, is to use "Trim" function but it doesn't solve the issue. Trim, Ltrim or Rtrim just delete spaces but it doesn't delete line feed.

In VB.Net a line feed can easily be removed by this code snippet below:

Dim strNoLineFeed As String = String_with_Line_Feed.Replace(vbCr, "").Replac…

Linux bash script copy folders and files from list

In Linux special characters such as "#", "-" and other special characters cannot be access directly either by manual copy or via script. For example this path below it has the sharp "#" key:
/usr/dfiles/$line/Tasks/#msgs/
cp "/usr/dfiles/$line/Tasks/#msgs/*.eml" "/mnt/NAS/Tasks1/line/"
Even though the path is enclosed by quotation marks, Linux system will show "No such file or directory".

Since the system is unable to find the "#msgs" directory.

As a work around in this issue is to append "--" double dash before the cp command and everything will work fine.

So, this command below will work.

cp  -- "/usr/dfiles/$line/Tasks/#msgs/*.eml" "/mnt/NAS/Tasks1/line/"
Copying one folder is quite practical to do it by hand rather by script.
But if you are copying hundreds or thousands of folders, doing it manually is quite painful.
To copy hundreds or thousands of folders to another folder the pra…

Vbscript send email via Office 365

Sending automated email via Office 365 account requires the use of SSL or in some instances you need to use SSL and TLS both enabled on the script.

Below is an example that works fine using Vbscript.

This is useful if you need to automate email messages via Task Scheduler or Windows event attached to this script, when the event is triggered the script will execute the VBS file and send the message.

Modify the message subject, body and of course, the email domain name, user and password.

Open notepad copy and paste the code, save as "filename.vbs"

The quotes are important when doing save as via notepad or else the file will be save as .txt.

Enjoy! Cheers!

'=======================
Dim xstrAll(), strMessage,intupper()

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Send the mail
SentMail


Sub SentMail

strMessage =  strMessage & "Your other message..."

strTo= "your.office365@domain_account.com" 
strFrom="your.office365@domain_accou…

Copy folder/file to multiple folders

Copy a single folder to multiple folders?

Copy a file to multiple folders?

This can be done easily using PowerShell script.

Script below requires PS 3.0, but it can easily be tweak for other version.

Here's the script:

#++++++++++++++++++++++++++++++
$source_folder="D:\xfolder\United Folders"
dir -Directory "D:\Unity\Project_016\" | ForEach-Object {
write-host $_.fullname
Copy-Item -Path $source_folder -Destination $_.FullName
}
#++++++++++++++++++++++++++++++

What the script does is the $source_folder is to be copied to all folders in the destination.

Basically, the "United Folders" is to be copied to the root of the sub folder in destination folder which is "D:\Unity\Project_016\".

Example:
D:\Unity\Project_016\01
D:\Unity\Project_016\02
D:\Unity\Project_016\03

After executing the script, the folders will look like this:
D:\Unity\Project_016\01\United Folders
D:\Unity\Project_016\02\United Folders
D:\Unity\Project_016\03\United Folders

It dep…

Hide files in Linux

Linux protect file from deletion

To protect file from deletion in Linux system, the chattr command is able to set the attributes that protects the file.

chattr +a my_protected_file.txt

chattr +a  == means that the file can be appended and the file can't be deleted as well.

To set the file to immutable, "+i"  attribute can be used.

chattr +i the_protected_file.txt

Immutable file is protected from deletion and the original contents of the file is also preserved because no changes can be made.

This command below:

ls xx*.txt >> the_protected_file.txt

The command above will show "permission denied" if the file is immutable.

If the file is set with +a, then the above command will append the output of "ls" to the file.

To unset or removed the attribute use the minus sign, "-a", "-i".

For example, chattr -a the_protected_file.txt or  chattr -i the_protected_file.txt

To know more about chattr type the command below:

man chattr
chattr --help
info chattr

This wiki link shows …