Skip to main content

Posts

Showing posts with the label rosary

Bash slice string in Linux Shell

Strings are quite basic in any scripting or programming languages. If a journey to a thousand miles starts with a single step, in the programming world the journey starts with a string called “Hello World” and beyond “Hello World” pseudocode and algorithm will keep the journey going.   Strings in scripting or programming are just group of characters. So, if string is a group of characters then it can be slice by character or a sub-string can be taken from the string. To slice a string in Bash, a syntax which is part of the Bash library can be used. Syntax is: ${string_to_be_sliced:slice_start_position:slice_end_position} Example string: slicethestring=“Hello Algorithm World” The string is stored in a variable: slicethestring To get the sub-string “Algorithm World”. Code will be:   echo ${slicethestring:6:23} #start the slice at position 6 till position 23 Another way to slice the string from a specified start position till the end; is to tell Bash the star...

Read or get the list of contents on S3 bucket

S3 or Simple Storage Service bucket is quite handy to store files or any data on AWS cloud. As with any storage, online or offline organizing the data is quite an issue. When there are a lot of files of data on the storage; finding the data that you will need will be difficult. Especially, if the data or bucket is not organized properly. And even if the data has been organized by folders with proper time stamp but no specific data catalog to classify which one is which one it is quite a challenge to find or get the data on time. S3 is ideal for backup, since backup is often accessed only when it is needed. So, familiarization of the backup folder structure is necessary. In order to find or get easily the data, listing the contents of the S3 bucket is a good option when unable to find the files or data needed. Once the list is ready, opening the list via editor such as notepad and searching or finding thru the editor will provide an option to find things quickly and easily. ...

PowerShell switch case call function

Code below collect user input and uses switch case statement to check if the input matches, and if it matches a function is called that will execute commands. Here’s the code: #get or read from user input $computer_name = read-host ( "Enter Computer Name:" )   switch ( $computer_name )   {     #if the input is computer_1 then function func_comuputer1 is called   computer_1     { func_computer1 }     computer_2     { func_computer2 }   }     #function called if computer_1 is the input function func_computer1 {   write-host "You entered Computer_1" #or replaced with other function like reboot / shutdown /or other commands #Restart-Computer -ComputerName computer_1   }   #function called if computer_2 is the input function func_computer2 {   write-host "You entered Computer_2" #or replaced with other function like reboot / shutdown /or other c...

How to upload to S3 using PowerShell

Uploading to S3 using PowerShell is quite easy. Here’s the code: $accesskey = '123' $secretkey = '456' $dregion =   'us-east-1'   Write-S3Object -AccessKey $accesskey -SecretKey $secretkey -Region $dregion -BucketName   -File C:\Temp\test-file.txt #Replace NameofthebucketinS3 with the folder name found in S3 # test-file.txt is the file that will be uploaded to S3 and is located on c:\Temp #Change the folder location c:\Temp and the file to be uploaded #Above code will upload the file to the root of the S3 Bucket     #If need to upload a file to a specific subfolder in S3 bucket used the code below   $accesskey = '123' $secretkey = '456' $dregion =   'us-east-1'   Write-S3Object -AccessKey $accesskey -SecretKey $secretkey -Region $dregion -BucketName NameofthebucketinS3/SubFolderBucket -File C:\Temp\test-file.txt   Use forward slash to indicate the sub folder path. So the syntax would be...

Linux find accessed and modified files

Finding accessed and modified files might be necessary at times to check or for audit purposes. If files kept in a folder or directory has been accessed or modified but should not be the case then something dubious is going on.  In Linux finding accessed and modified files can be done in a one liner command. find /home -type f -amin -60 || -mmin -60 -print Above command will find or show any files accessed within the last 60 minutes with the option "-amin" and it will show also the files modified within the last 60 minutes with the option "-mmin". A shell script can be created and further processing can be done when files are detected. The time can be adjusted if there's a need, but a more robust solution to check any accessed or modified files should be a file system watcher, but above command is quite helpful to check any activity that should not be occurring. Cheers..till next time!   ================================ Free Android Apps: Click  links below to f...

Create a new text file with content in Linux

Touch command in Linux will create an empty file in Linux command line. If no other parameters is specified whether a line will be inserted to the newly created file. Cat command is for reading files via command line but it can also be used to create a file in Linux terminal window command line. Cat command below will create a file called “test_comment.txt” and with the content or the line of “Hello World of Touch and Create File” on the file created. Here’s the shell command: cat  <( echo “Hello World of Touch and Create File”)  >  test_comment.txt Note that there is no space between “<(“, if there is a space then the command will not work as expected. Touch command to create a new file and also insert a new line or insert a string on the newly created file. Here’s the shell command: touch touch_file_comment.txt; echo “Hello World of Touch, insert this line.” >  touch_file_comment.txt Basically, the command exec...

PowerShell get time zone setting

Time zone settings in computers has a lot of purposes, of course it can tell you the time when to knock off from work. 😊 But there’s a lot of other purposes and having a time zone that is different from software application that is expecting, then unexpected issues may arise. Database must be in sync with a correct time zone or else time stamp on database records will be inaccurate, system logs must also be in a correct time zone or else when diagnosing the logs or data will be an issue. There are other issues that requires to have a correct time zone setting set on your computer. Checking whether the correct time zone is set on your computer can easily be done in PowerShell. So, how to get time zone settings in PowerShell? Here’s the code: Get-CimInstance Win32_TimeZone | select caption Windows 10 does support a setting with multiple time zone, here’s an output from above PowerShell with two time zone set on a computer. Sample output: caption  ...

How to check office version from command line

The are quite a few ways to check office version it can be done via registry, PowerShell or VBScript and of course, good old command line can also do it. Checking Windows office version whether it is Office 2010, Office, 2013, Office 2016 or other version is quite important to check compatibility of documents; or just a part of software inventory. For PowerShell this simple snippet can check the office version: $ol = New-Object -ComObject Excel.Application $ol . Version The command line option will tell you where’s the path located; the result will also tell whether office is 32-bit, 64-bit and of course the version of the office as well. Here’s the command that will check the office version and which program directory the file is located which will tell whether it’s 32-bit or 64-bit. Command to search for Excel.exe: DIR C:\ /s excel.exe | find   /i "Directory of"  Above command assumes that program files is on  C: drive. Sample O...