This is how to How to call a shell script from python code
import subprocess
subprocess.call(['sh shell_script.sh arguments'])
or
import sys, os
os.system("sh shell_script.sh arguments")
Output Example
IT – Engineering – Cloud – Finance
IT, Engineering, Entrepreneurship, Sports, Finances, Life, Success, Failure
import subprocess
subprocess.call(['sh shell_script.sh arguments'])
or
import sys, os
os.system("sh shell_script.sh arguments")
Output Example
Some IT DevOps, SysAdmin, Developer positions require the knowledge of basic linux Operating System. Most of the time, we know the answer but forget them when we don’t practice very often. This refresher will help you prepare for the linux portion of your IT interview by answering some gotcha Linux Questions for IT DevOps and SysAdmin Interviews.
I- Networking:
II- Operating System
1&1 Web Hosting
Boot ROM | Firmware. Part of Hardware system BootROM firmware is activated |
POST | Power-On Self Test initializes some hardware interfaces and verifies that sufficient memory is available and in a good state. |
EFI | Extensible Firmware Interface EFI does basic hardware initialization and selects which operating system to use. |
BOOTX | boot.efi boot loader load the kernel environment |
Rooting/Kernel | The init routine of the kernel is executed boot loader starts the kernel’s initialization procedure Various Mach/BSD data structures are initialized by the kernel. The I/O Kit is initialized. The kernel starts /sbin/mach_init |
Run Level | mach_init starts /sbin/init init determines the runlevel, and runs /etc/rc.boot, which sets up the machine enough to run single-user. rc.boot figures out the type of boot (Multi-User, Safe, CD-ROM, Network etc.) |
III- File System
IV- Databases
V- Scripting
Learn more at http://career.guru99.com/top-50-linux-interview-questions/
Real Time Linux Jobs
Declaration:
$states=@{“Alberta” = “Calgary”; “British Columbia” = “Vancouver”; “Ontario” = “Toronto” ; “Quebec” = “Montreal”}
Name _____ |
Value _______ |
Alberta | Calgary |
British Columbia | Vancouver |
Ontario | Toronto |
Quebec | Montreal |
Add new key-value in hashtable:
$states.Add(“Manitoba”,”Winnipeg”)
Remove key-value in hashtable:
$states.Remove(“Manitoba”,”Winnipeg”)
Change value in hashtable:
$states.Set_Item(“Ontario”,”Ottawa”)
Retrieve value in hashtable:
$states.Get_Item(“Alberta”)
Find key in hashtable:
$states.ContainsKey(“Alberta”)
Find Value in hashtable:
$states.ContainsValue(“Calgary”)
Count items in hashtable:
$states.Count
Sort items by Name in hashtable:
$states.GetEnumerator() | Sort-Object Name -descending
Sort items by Value in hashtable:
$states.GetEnumerator() | Sort-Object Value -descending
Declaration:
my %hash = (); #Initialize a hash
my $hash_ref = {}; # Initialize a hash reference. ref will return HASH
Clear (or empty) a hash
for (keys %hash)
{
delete $hash{$_};
}
Clear (or empty) a hash reference
for (keys %$href)
{
delete $href->{$_};
}
Add a key/value pair to a hash
$hash{ ‘key’ } = ‘value’; # hash
$hash{ $key } = $value; # hash, using variables
Using Hash Reference
$href->{ ‘key’ } = ‘value’; # hash ref
$href->{ $key } = $value; # hash ref, using variables
Add several key/value pairs to a hash
%hash = ( ‘key1’, ‘value1’, ‘key2’, ‘value2’, ‘key3’, ‘value3’ );
%hash = (
key1 => ‘value1’,
key2 => ‘value2’,
key3 => ‘value3’,
);
Copy a hash
my %hash_copy = %hash; # copy a hash
my $href_copy = $href; # copy a hash ref
Delete a single key/value pair
delete $hash{$key};
delete $hash_ref->{$key};
Hash tables are called dictionary in python.
Declaration:
dict = {‘Name’: ‘Zara’, ‘Age’: 7, ‘Class’: ‘First’}
Accessing Values
print “dict[‘Name’]: “, dict[‘Name’]
print “dict[‘Age’]: “, dict[‘Age’]
Output:
dict[‘Name’]: Zara
dict[‘Age’]: 7
Updating Dictionary
dict = {‘Name’: ‘Zara’, ‘Age’: 7, ‘Class’: ‘First’}
dict[‘Age’] = 8; # update existing entry
dict[‘School’] = “DPS School”; # Add new entry
Delete Dictionary Elements
#!/usr/bin/python
dict = {‘Name’: ‘Zara’, ‘Age’: 7, ‘Class’: ‘First’}
del dict[‘Name’]; # remove entry with key ‘Name’
dict.clear(); # remove all entries in dict
del dict ; # delete entire dictionary
sh-3.2# vi reverse.sh
#### Start Script #####
#!/bin/bash
input_string=”$1″
reverse_string=””
input_string_length=${#input_string}
for (( i=$input_string_length-1; i>=0; i– ))
do
reverse_string=”$reverse_string${input_string:$i:1}”
done
echo “$reverse_string”
##### End Script #####
Let’s run it:
sh-3.2# chmod 775 reverse.sh
sh-3.2# ./reverse.sh Etienne
enneitE
#Let’s use the script reverse.ps1 below.
######
$string=”Etienne”
$string_array=$string -split “”
[array]::Reverse($string_array)
$string_array -join ”
#####Output#####
PS C:\Users\etienne_noumen\Documents\Etienne\Scripting> .\reverse.ps1
E t i e n n e
enneitE
([regex]::Matches($String,’.’,’RightToLeft’) | ForEach {$_.value}) -join ”
::Note: ReverseStr also calls StrLen
::and string length is not greater than 80 chars
:: but can be changed.
@echo off
SetLocal EnableDelayedExpansion
cls
set Str=Etienne
call :StrLen %Str%
echo Length=%Len%
call :ReverseStr %Str%
echo String=%Str%
echo Reverse Str=%Reverse%
exit /b
::—————-
:: Calc Var Length
::—————-
:: %*=Str to Check
:: Returns %Len%
:: —————
:StrLen %*
set Data=%*
for /L %%a in (0,1,80) do (
set Char=!Data:~%%a,1!
if not “!Char!”==”” (
set /a Len=%%a+1
) else (exit /b)
)
exit /b
::—————
:: Reverse String
::—————
:: %* Str to Reverse
:: Returns %Reverse%
::——————
:ReverseStr %*
set Data=%*
call :StrLen %Data%
for /L %%a in (!Len!,-1,0) do (
set Char=!Data:~%%a,1!
set Reverse=!Reverse!!Char!
)
exit /b
def reverse_string(a_string)
return a_string[::-1]
reverse_string(“etienne”) returns “enneite”
Source:
BIOS |
Basic INPUT/OUTPUT System. Executes MBR |
MBR |
Master Boot Record Executes GRUB |
GRUB |
Grand Unified Bootloader Executes kernel |
KERNEL |
Kernel Executes /sbin/init |
INIT |
Init Executes Run level programs |
Run Level | Run Level Programs are executed from /etc/rc.d/rc*.d/ |
Source: