prompt and read input variables from keyboard

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

Let’s find how to prompt and read input variables from keyboard while executing a script using shell, perl, python, batch and powershell (windows and Linux)

  • On Linux via shell

    read -p “Enter your name: ” name
    echo “Hi, $name. Let’s be friend!”

  • On Windows via powershell

    $name=read-host “Enter your name:”
    write-host “Hi $name, Let’s be friend!”

  • On Windows via batch

    Set /p Name=”Enter your name:”
    echo “Hi %name%, Let’s be friend!”

  • On Windows or Linux via perl

    print “Enter your name “;
    my $name = ;
    chomp $name; # Get rid of newline character at the end
    print “Hello $name, let’s be friend”;

  • On Windows or Linux via python

    name=input(“Enter your name: “)
    print (“Hello ” + name + ” let’s be friend”)

Replace all instances of a string in a file

How to Replace all instances of a string in a file?

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

How to Replace all instances of a string in a file?

  1. Open the file in read mode using the open() function.
  2. Read the contents of the file into a string using the read() method.
  3. Use the replace() method to replace all instances of the target string with the new string.
  4. Open the file in write mode using the open() function.
  5. Write the modified string to the file using the write() method.
  6. Close the file using the close() method.

Here is an example code snippet:

How to Replace all instances of a string in a file?
How to Replace all instances of a string in a file?

This will replace all instances of old_string with new_string in the file file.txt.

# Open the file in read mode
with open(‘file.txt’, ‘r’) as f:
# Read the contents of the file into a string
contents = f.read()

# Replace all instances of the target string
contents = contents.replace(‘old_string’, ‘new_string’)

# Open the file in write mode
with open(‘file.txt’, ‘w’) as f:
# Write the modified string to the file
f.write(contents)

Get 20% off Google Google Workspace (Google Meet) Standard Plan with  the following codes: 96DRHDRA9J7GTN6
Get 20% off Google Workspace (Google Meet)  Business Plan (AMERICAS) with  the following codes:  C37HCAQRVR7JTFK Get 20% off Google Workspace (Google Meet) Business Plan (AMERICAS): M9HNXHX3WC9H7YE (Email us for more codes)

Active Anti-Aging Eye Gel, Reduces Dark Circles, Puffy Eyes, Crow's Feet and Fine Lines & Wrinkles, Packed with Hyaluronic Acid & Age Defying Botanicals

# Close the file
f.close()

Shell script to replace all instances of a string in a file on Linux & Windows.

  • On Linux via bash script

    sed “s/$stringToReplace/$replaceWith/g” $File_Name > $File_Name

  • On Windows using Powershell

    ( get-content $File_Name ) | % { $_ -replace $stringToReplace, $replaceWith } | set-content $File_Name

  • On Windows using Batch

    set str=teh cat in teh hat
    echo.%str%
    set str=%str:teh=the%
    echo.%str%

    Script Output:
    teh cat in teh hat
    the cat in the hat

  • On Windows or Linux using Perl

    perl -pi.orig -e “s///g;”

  • On Windows or Linux using Python

Source:

  1. http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir

Search all files containing a specific string

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

How to search all files containing a specific string on Linux and Windows?

  • On Linux

    grep -rnw ‘directory’ -e “pattern”
    grep –include=\*.{txt,log} -rnw ‘directory’ -e “pattern”
    This will only search for files with .txt or .log extension.
    grep –exclude=*.txt -rnw ‘directory’ -e “pattern”
    This will exclude files with .txt extensions.

  • On Windows

    CD Location
    FINDSTR /L /S /I /N /C:”pattern” *.log

Browse the internet via command line

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

How to browse the internet via command line on Linux and Windows?

  • On Linux

    lynx http://google.ca
    If you don’t have lynx on your linux installation, you will have to install it. On Linux Red hat, install it like this:
    yum list lynx (to check the availability of the package)
    yum -y install lynx (to install the package)
    you can also use: curl -0 http://yoursite/index.html to get the source code of a specific file.

  • On Windows

    start /max http://google.ca
    Will open the url using your default browser.

Check how many CPU cores on Windows and on Linux

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

How to check how many CPU cores I have on Windows & Linux?

What is a core in a CPU?
In summary, a core is a small CPU or processor built into a big CPU or CPU socket. It can independently perform or process all computational tasks. From this perspective, we can consider a core to be a smaller CPU or a smaller processor within a big processor.
Today, CPUs have been two and 18 cores, each of which can work on a different task. A core can work on one task, while another core works a different task, so the more cores a CPU has, the more efficient it is.

Open a command prompt (Windows) or Terminal (Linux) and type:

  • Windows: WMIC CPU Get /Format:List
    Capture_Check_CPU_Cores
  • Linux: cat /proc/cpuinfo | grep processor | wc -l
    For more details on Linux: ls /sys/devices/system/cpu/

What does 4 CPU cores mean?
A quad-core CPU has four processing cores in a single chip. It is similar to a dual-core CPU, but has four separate processors (rather than two), which can process instructions at the same time.

un-archive a folder silently in Windows

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

Powershell script to un-archive a folder silently in Windows

Let’s continue with our automation scripting tool series. Doing things on windows by using the mouse manually is fun until you run into the need to go to a major OS upgrade and have tons of applications to reinstall. To avoid human errors and save lots of time, you can write a script  to pick up your archived applications like tomcat zip files and unarchive it. This powershell scripts shows you how to unarchive a zip file silently.

#Unzip FIle Function
function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}

# Call the function to unzip

$Origin_Zip_File=”C:\Document\Test.zip”

$Destination_Folder=”C:\Document\Test_Unzipped”

Get 20% off Google Google Workspace (Google Meet) Standard Plan with  the following codes: 96DRHDRA9J7GTN6
Get 20% off Google Workspace (Google Meet)  Business Plan (AMERICAS) with  the following codes:  C37HCAQRVR7JTFK Get 20% off Google Workspace (Google Meet) Business Plan (AMERICAS): M9HNXHX3WC9H7YE (Email us for more codes)

Active Anti-Aging Eye Gel, Reduces Dark Circles, Puffy Eyes, Crow's Feet and Fine Lines & Wrinkles, Packed with Hyaluronic Acid & Age Defying Botanicals

Expand-ZIPFile –File $Origin_Zip_File –Destination $Destination_Folder

Script to Stop Application Pools on Windows

AI Dashboard is available on the Web, Apple, Google, and Microsoft, PRO version

VB script to Stop Application Pools on Windows IIS 6

As  SysAdmin, We sometimes need to auto-stop some application pools in order to run a specific task like IIS logs cleanup.

This script will detect all application pools that are running and stop them.

=====================
myComputer = “.”
Set objWMIService = GetObject (“winmgmts:\\” & myComputer & “\root\microsoftiisv2”)
Set colItems = objWMIService.ExecQuery (“Select name from IISApplicationPoolSetting where AppPoolState = 2”)
For Each objItems In colItems
poolname=objItems.name
WScript.Echo poolname
AppPoolStop(poolname)
Next
Function AppPoolStop(PoolName)
set PoolcolItems = objWMIService.ExecQuery (“Select name from IISApplicationPool where name='” & poolname & “‘”)
For Each objItem In PoolcolItems
objitem.Stop
Next
End Function
===============
Enter that script in a text file, save it with extension “.vbs”. Copy it at C:\Windows\System32\
Run it manually or via a batch scheduler.
Thanks to Euk-marie. See the equivalent script by Euk-Marie to start the App Pool at https://www.eukhost.com/forums/f15/start-application-pool-simple-script-8937/
Pass the 2023 AWS Cloud Practitioner CCP CLF-C02 Certification with flying colors Ace the 2023 AWS Solutions Architect Associate SAA-C03 Exam with Confidence Pass the 2023 AWS Certified Machine Learning Specialty MLS-C01 Exam with Flying Colors

List of Freely available programming books - What is the single most influential book every Programmers should read



#BlackOwned #BlackEntrepreneurs #BlackBuniness #AWSCertified #AWSCloudPractitioner #AWSCertification #AWSCLFC02 #CloudComputing #AWSStudyGuide #AWSTraining #AWSCareer #AWSExamPrep #AWSCommunity #AWSEducation #AWSBasics #AWSCertified #AWSMachineLearning #AWSCertification #AWSSpecialty #MachineLearning #AWSStudyGuide #CloudComputing #DataScience #AWSCertified #AWSSolutionsArchitect #AWSArchitectAssociate #AWSCertification #AWSStudyGuide #CloudComputing #AWSArchitecture #AWSTraining #AWSCareer #AWSExamPrep #AWSCommunity #AWSEducation #AzureFundamentals #AZ900 #MicrosoftAzure #ITCertification #CertificationPrep #StudyMaterials #TechLearning #MicrosoftCertified #AzureCertification #TechBooks

Top 1000 Canada Quiz and trivia: CANADA CITIZENSHIP TEST- HISTORY - GEOGRAPHY - GOVERNMENT- CULTURE - PEOPLE - LANGUAGES - TRAVEL - WILDLIFE - HOCKEY - TOURISM - SCENERIES - ARTS - DATA VISUALIZATION
zCanadian Quiz and Trivia, Canadian History, Citizenship Test, Geography, Wildlife, Secenries, Banff, Tourism

Top 1000 Africa Quiz and trivia: HISTORY - GEOGRAPHY - WILDLIFE - CULTURE - PEOPLE - LANGUAGES - TRAVEL - TOURISM - SCENERIES - ARTS - DATA VISUALIZATION
Africa Quiz, Africa Trivia, Quiz, African History, Geography, Wildlife, Culture

Exploring the Pros and Cons of Visiting All Provinces and Territories in Canada.
Exploring the Pros and Cons of Visiting All Provinces and Territories in Canada

Exploring the Advantages and Disadvantages of Visiting All 50 States in the USA
Exploring the Advantages and Disadvantages of Visiting All 50 States in the USA


Health Health, a science-based community to discuss health news and the coronavirus (COVID-19) pandemic

Today I Learned (TIL) You learn something new every day; what did you learn today? Submit interesting and specific facts about something that you just found out here.

Reddit Science This community is a place to share and discuss new scientific research. Read about the latest advances in astronomy, biology, medicine, physics, social science, and more. Find and submit new publications and popular science coverage of current research.

Reddit Sports Sports News and Highlights from the NFL, NBA, NHL, MLB, MLS, and leagues around the world.

Turn your dream into reality with Google Workspace: It’s free for the first 14 days.
Get 20% off Google Google Workspace (Google Meet) Standard Plan with  the following codes:
Get 20% off Google Google Workspace (Google Meet) Standard Plan with  the following codes: 96DRHDRA9J7GTN6 96DRHDRA9J7GTN6
63F733CLLY7R7MM
63F7D7CPD9XXUVT
63FLKQHWV3AEEE6
63JGLWWK36CP7WM
63KKR9EULQRR7VE
63KNY4N7VHCUA9R
63LDXXFYU6VXDG9
63MGNRCKXURAYWC
63NGNDVVXJP4N99
63P4G3ELRPADKQU
With Google Workspace, Get custom email @yourcompany, Work from anywhere; Easily scale up or down
Google gives you the tools you need to run your business like a pro. Set up custom email, share files securely online, video chat from any device, and more.
Google Workspace provides a platform, a common ground, for all our internal teams and operations to collaboratively support our primary business goal, which is to deliver quality information to our readers quickly.
Get 20% off Google Workspace (Google Meet) Business Plan (AMERICAS): M9HNXHX3WC9H7YE
C37HCAQRVR7JTFK
C3AE76E7WATCTL9
C3C3RGUF9VW6LXE
C3D9LD4L736CALC
C3EQXV674DQ6PXP
C3G9M3JEHXM3XC7
C3GGR3H4TRHUD7L
C3LVUVC3LHKUEQK
C3PVGM4CHHPMWLE
C3QHQ763LWGTW4C
Even if you’re small, you want people to see you as a professional business. If you’re still growing, you need the building blocks to get you where you want to be. I’ve learned so much about business through Google Workspace—I can’t imagine working without it.
(Email us for more codes)

error: Content is protected !!