Skip to main content

Posts

Showing posts from 2020

Use Linux Bash to query or automate listing the contents of an S3 bucket.

Below is a Bash script that will query a bucket with the current date specified on the system. Querying or listing the contents of the S3 bucket is quite a good strategy. Let's say if you need to make sure that important backups are copied or present on S3 bucket.  Or you need to monitor what are the contents being dumped to a specific S3 bucket. Automating querying S3 contents in Linux using Bash scripting is a good idea. Below is a code that works fine on a Linux system. #!/bin/bash varDate=$(date +%Y-%m-%d) aws s3api list-objects --bucket "name_of-the-bucket" --prefix sub_directory_bucket --query 'Contents[?LastModified>=`'${varDate}'`][].{Key: Key, Size: Size, LastModified: LastModified}' >> /tmp/s3_server_files_$varDate.txt The script can be configured on a cron task and runs on a daily basis then the date is automatically supplied by the bash script and data is saved on /tmp/ and file will not be overwritten since filename is based on date. ...

Python basic if else and or comparison code

Comparing input or variables is a quite a common task to do when creating programs. In Python it can be done in a lot of ways, this example code below shows how it’s being done using “if else” and “or” statement. Here’s the example code below: #Get user input requires Python 3 input1 = input("1. Type something to test this out : ") input2 = input("2. Type something to test this out : ") input3 = input("3. Type something to test this out : ")   #variable initialization is important or else it will result to NameError: name 'variable_name' is not defined checkinput1 = 0 checkinput2 = 0 checkinput3 = 0 noinput = 1   #int(input1) convert the input1 string to an integer if (int(input1) > 40):   checkinput1 = "1" elif ( int(input2) > 40):   checkinput2 = "1" elif ( int(input3) > 40):   checkinput3 = "1" else:   noinput = 0   if (checkinput1 or checkinput2 or checkinput3 ==...

Difference between incremental and differential backup

Differential or Incremental backup are part of the options that need to be selected when installing a backup software. Or the system admin has to choose which backup strategy he or she will adapt. Backup is very important so you have something to rely on when disaster strikes. So, what’s the difference between differential and incremental backup? Which one is better? Differential backup – contains  the files that have changed since the last full backup. So, if the full backup was Sunday, Monday will have files that changed since  Sunday  backup. For the differential backup of Tuesday, it will contain the files of Monday and the files of Tuesday. Differential backup = requires large space since every differential backup has the files that had changed since the last full backup Incremental backup – backup only the changed data since the last backup. So, if the Full backup was done on Sunday; Monday backup will only have the data that has changed since last Sunday ...

Use a windows external keyboard in Macbook Pro

Using a windows external keyboard for Macbook Pro is quite straight forward since the letter or alphabets are the same. But wait, Windows keyboard don’t have the “command” key nor the “option” key. If you are a keyboard junkie, you might miss Ctrl + C , and Ctrl + V when using Macbook. The “command” key in Macbook has equivalent key on a Windows keyboard, which is the “Windows” key. So, to press “Command key” + C which is the shortcut for copy. In a windows keyboard, press “Windows key” + C and it will perform the copy command. Keyboard Macbook command: “Command key” + C [copy] == Equivalent in Windows keyboard is: “Windows key” + C “Command key + V [paste] == Equivalent in Windows keyboard is: “Windows key” + V Shift + Home in windows keyboard, will highlight the current cursor position until the first character on the line. In Macbook, some application may not recognize this command. The equivalent of shift + home on a windows keyboard is: “Windows key” + shift + ...

Python create multiple choices for if statement

How to compare multiple choices in Python if statement? In an if else statement, if case sensitivity is a concern on the response or input from the user. Then the expected response should be defined on the if statement. Of course, there’s a good workaround on this kind of scenario like converting all input to lowercase or uppercase then start comparing or matching. Basically, the code below is for illustration purposes only. Converting the input to lowercase or uppercase is a good option, if the program is expecting a string input. However, code illustrated below will not be useful if the input is a number. In which case, converting the input to lowercase or uppercase will not help. Anyway, code below uses the string T, True or true as possible input that will display this message” You must have seen the sun! Or hoping to see the sun at the end of the tunnel!” if it matches “T, True or true”. If the input is TRUE, or other letter other than the characters mentioned above it...

Python if else pass or continue after evaluating input

Beginning in Python programming? If else statement is quite a basic statement in any programming language. If else is used in evaluating conditions or basically, it will tell the program what to do next if a specified match or input is encountered. In if else statement, depends on the conditional statement that is set then the next logic will determine on what action or execution will be performed. For example, after a match pattern occurs then the next statement will execute an action but sometimes after a match occurs you don't want to do anything instead the else statement will show what action or logic to be executed. In Python "continue" statement does not mean that it will continue to execute the code after the "continue" statement, instead it will break that execution and goes to the top of the code and continue the next course of action. However, "pass" statement in Python will mean literal "pass". So, if "pass" is...

Turn off Microphone settings in Windows 10

 How to turn off or disable Mic or Microphone settings in Windows 10? Steps below shows how to turn off Microphone settings in Windows 10. One method is to type: 'settings' on the search bar See image below: Another method, to bring up the settings option is to press "Windows Key + i key" together. See image below: Either method is used to bring up the settings, once the settings window is open. Type: micro or complete the word microphone Basically, the window settings has some sort of regex that matches the string that is being typed. See image below: The image above shows how to turn off the Microphone, if the login user has admin rights then the "change" option will be enabled. To turn it back on, just slide the switch on the microphone settings and it will be turned on. To test whether the microphone is working or not, Windows 10 provided a recorder called "voice recorder" app. On the search area just type: record and the voice recorder will be...

PowerShell read text file at a specific or certain lines

Reading log files or text file is quite basic and log files should be reviewed or else recording the logs if of no point. PowerShell code below read the 2 nd line of a specific text file specified on the path.   $logs = get-content c:\dev\log1.txt   "Line number 2 in log1.txt is: {0}" -f ( $logs [ 2 ] )     PowerShell code below uses a loop to read number of lines on a specific text file. $logs = get-content c:\dev\log1.txt   ForEach ( $line_number in 0 .. 10 ) {   "Line number $line_number is : {0}" -f ( $logs [ $line_number ] )}     Using above code, 0 is equal to line 1.   So, to read the first line code should be like this:     $logs = get-content c:\dev\log1.txt   "Line number 1 in log1.txt is: {0}" -f ( $logs [ 0 ] )     To read the last line: $logs = get-content c:\dev\xtest.txt -Tail 1 $logs     If above command will return an emp...

Use PowerShell in Excel VBA

VBA in Excel is very helpful since it can run things without any human intervention, or technically it can run task and automate things and just get the result. VBA coupled with PowerShell can even be more interesting. Of course, there is always some drawback or pros and cons. Bad actor can take advantage of VBA and PowerShell to run malicious software on user’s computer. For most users who are not aware or doesn’t believe that VBA and PowerShell can be used to steal data, one common reaction is; Is it possible? Or you are just trying to exaggerate and scare people? As the odds say, to see is to believe. Or to see it in action is one thing and trying to educate users is another thing. Cyber Security is a task that everyone should be a part of, a chain is useless if one its link is weak. Which is basically, true in digital world. The company may spend thousands of moneys on Firewall, Anti-Virus and other devices or software to thwart attack but just a simple click on a Phishin...