0% found this document useful (0 votes)
26 views7 pages

Script

The document provides a comprehensive overview of various Linux commands, scripting techniques, and database concepts. It covers topics such as process management, file handling, SQL keys, PL/SQL functions and procedures, and backup strategies. Additionally, it includes examples of shell scripts for automation tasks and system monitoring.

Uploaded by

rekha.ubbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Script

The document provides a comprehensive overview of various Linux commands, scripting techniques, and database concepts. It covers topics such as process management, file handling, SQL keys, PL/SQL functions and procedures, and backup strategies. Additionally, it includes examples of shell scripts for automation tasks and system monitoring.

Uploaded by

rekha.ubbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

find /home -mtime +30 -daystart

grep -RiIl 'search' | xargs sed -i 's/search/replace/g'

A zombie process is a process whose execution is completed but it still has an


entry in the process table. Zombie processes usually occur for child processes, as
the parent process still needs to read its child's exit status.

The $# shows total number of arguments passed to the script.

Each file contains an index number known as "inode" which is comprised of metadata
about the associated file.
Soft links are link to the file name and can reside on different filesytem as well;
however hard links are link to the inode of the file and have to be on the same
filesytem as that of the file. Deleting the original file makes the soft link
inactive (broken link) but does not affect the hard link (Hard link will still
access a copy of the file)
-----------------------------
$@ treats each quoted arguments as separate arguments but $* will consider the
entire set of positional parameters as a single string.
---------
sed command-

sed is a stream editor. It provides the capability to modify, insert, delete,


format the text data at command line itself.

awk command-

awk is programming language generally used for text processing and formatting. It
provides the facility to specify pattern, command/actions on the command line or in
a program file to process the text and generate the formatted report by
manipulating the data available in datafile.

ou can use date command to find date of N days before, then using grep to search in
your text file.

grep `date +%Y-%m-%d -d "5 days ago"` test.txt

find . -type f -regextype posix-egrep -regex ".*CAPTURE04\.[0-9]{14}\.jpg" -exec


bash -c \
'fn=${0##*/}; d=${fn:10:-4};
[[ $d -ge 20171020083000 && $d -le 20171022093000 ]] && echo "$0"' {} \;
find ./ -type f -exec sed -i 's/string1/string2/g' {} \;

These are some important difference between primary key and foreign key in SQL-

Primary key cannot be null on the other hand foreign key can be null.

Primary key is always unique while foreign key can be duplicated.

Primary key uniquely identify a record in a table while foreign key is a field in a
table that is primary key in another table.

There is only one primary key in the table on the other hand we can have more than
one foreign key in the table.

#!/bin/bash
/usr/bin/find /path/to/files/ -type f -name '*.jpg' -mtime +15 -exec mv {}
/path/to/archive/ \;
/usr/bin/find /path/to/archive/ -type f -name '*.jpg' -mtime +30 -exec rm {} \;

By default primary key adds a clustered index on the other hand foreign key does
not automatically create an index, clustered or non-clustered. You must manually
create an index for foreign key.

-------------
Function: The main purpose of a PL/SQL function is generally to compute and return
a single value. A function has a return type in its specification and must return a
value specified in that type.

Procedure: A procedure does not have a return type and should not return any value
but it can have a return statement that simply stops its execution and returns to
the caller. A procedure is used to return multiple values otherwise it is generally
similar to a function.

Package: A package is schema object which groups logically related PL/SQL types ,
items and subprograms. You can also say that it is a group of functions, procedure,
variables and record type statement. It provides modularity, due to this facility
it aids application development. It is used to hide information from unauthorized
users.
---------------
A trigger is a PL/SQL program which is stored in the database. It is executed
immediately before or after the execution of INSERT, UPDATE, and DELETE commands.
----------------
A stored procedure is a sequence of statement or a named PL/SQL block which
performs one or more specific functions. It is similar to a procedure in other
programming languages. It is stored in the database and can be repeatedly executed.
It is stored as schema object. It can be nested, invoked and parameterized.
-------------
The PL/SQL Function is very similar to PL/SQL Procedure. The main difference
between procedure and a function is, a function must always return a value, and on
the other hand a procedure may or may not return a value. Except this, all the
other things of PL/SQL procedure are true for PL/SQL function too.
------------
Exception is an error handling part of PL/SQL. There are two type of exceptions:
pre_defined exception and user_defined exception.
---------------
Daemons are services that provide several functions that may not be available under
the base operating system. Its main task is to listen for service request and at
the same time to act on these requests. After the service is done, it is then
disconnected and waits for further requests.
----------------
INDEX is a performance optimization technique that speeds up the data retrieval
process. It is a persistent data structure that associated with a Table (or View)
in order to increase performance during retrieving the data from that table (or
View).
SELECT t_13.value AS val13, t_17.value AS val17
FROM t_13
LEFT JOIN
t_17
ON t_13.value = t_17.value
UNION ALL
SELECT t_13.value AS val13, t_17.value AS val17
FROM t_13
RIGHT JOIN
t_17
ON t_13.value = t_17.value
WHERE t_13.value IS NULL
ORDER BY
COALESCE(val13, val17)
LIMIT 30---------------
------------
Using shell script, Create 10 directories and each will have 10 subdirectories....
Each subdirectory will have 10 files and each files will have some content.
#!/usr/bin/bash
#Automation is everything
for i in {1..10..1}
do
mkdir /home/amit/$i
for s in {1..10..1}
do
mkdir /home/amit/$i/$s
for k in {1..10..1}
do
touch /home/amit/$i/$s/$k.txt
echo "Hey their, how are you" >> /home/amit/$i/$s/$k.txt

done
done
done
----------

This will complete the above mentioned task

ps aux | egrep "Z|defunct


ps -o ppid= <Child PID>
kill -s SIGCHLD <Parent PID
kill -9 <Parent PID

A production support person/team is responsible for monitoring the production


servers, scheduled jobs, incident management and receiving incidents and requests
from end-users, analyzing these and either responding to the end user with a
solution or escalating it to the other IT teams.

A Problem is a series of incidents with an unknown root cause, whereas incident


arises as soon as something breaks or stops working disrupting normal service.
Incident handling is usually a reactive process whereas problem management is more
proactive. Incident management system aims at restoring services quickly whereas
problem management aims at finding a permanent fix.
Problem Management ensures that all resolutions or workarounds that require a
change are submitted through Change Management via an RFC. Change Management will
monitor the progress of these changes and keep Problem Management advised. Problem
Management is also involved in rectifying the situation caused by failed changes,
and has a major role to play as a Change Advisory Board (CAB) member.

9667566478

tar -cvf /tmp/backup.tar /etc /var


gzip /tmp/backup.tar
find /tmp/backup.tar.gz -mtime -1 -type -print &> /dev/null
if [ $? -eq 0]
then
echo "backup was created"
echo
echo "archieving backup"
scp /tmp/backup.tar.gz root@:ip:/path
else
echo "backup files"
fi

ping -c1 localhost &> /dev/null


if [$? -eq 0 ]
then
echo "pig works"
else
echo "not able to ping"
fi

STR="hello"
STR2=$STR
STR=$"{STR}WORLD"

function name () {
commands
}

is_file_exist() {
local file="$1"
[[ -f "$file"]] && return 0 || return 1
} 1 &&

#!/bin/sh

# Priority for the MySQL dump and rdiff-backup Min: 19 Max: -20
BACKUP_PRIO="19"
# New dumps will be stored here
BACKUP_TMP_DIR="/path/to/dumps/dir/"
# Incremental backup of dumps will be stored there
BACKUP_DIFF_DIR="/path/to/backup/dir/"
# MySQL user to use for DB connection in mysqldump
MYSQL_USER="root"
# put the root password here at your own risk ;)
MYSQL_PASSWD="root-password"

if [ ! -d $BACKUP_TMP_DIR ]; then
mkdir -p $BACKUP_TMP_DIR
fi

# Dump
databases=`mysql -u$MYSQL_USER -p$MYSQL_PASSWD -Bse "show databases" | grep -v
mysql | grep -v information_schema`
for i in $databases;
do
nice -n $BACKUP_PRIO mysqldump --single-transaction \
--quick --skip-extended-insert --routines -u$MYSQL_USER -p$MYSQL_PASSWD $i \
&gt; $BACKUP_TMP_DIR/$i.dump;
done

# Diff
nice -n $BACKUP_PRIO rdiff-backup $BACKUP_TMP_DIR $BACKUP_DIFF_DIR
nice -n $BACKUP_PRIO rdiff-backup --force --remove-older-than 7D $BACKUP_DIFF_DIR

removing files

for i in * ; do
dd if=/dev/urandom \
of="$i" \
bs=1024 \
count=`expr 1 + \
\`stat "$i" | grep 'Size:' | awk '{print $2}'\` \
/ 1024`
done

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

#!/bin/bash
RESTART="/sbin/service httpd restart"

# uncomment if you are using Debian / Ubuntu Linux


#RESTART="/etc/init.d/apache2 restart"

#path to pgrep command


PGREP="/usr/bin/pgrep"

# Httpd daemon name,


HTTPD="httpd"

# find httpd pid


$PGREP ${HTTPD}

if [ $? -ne 0 ] # if apache not running


then
# restart apache
$RESTART
fi

#!/bin/bash

USERNAME=someUser
HOSTS="host1 host2 host3"
SCRIPT="pwd; ls"
for HOSTNAME in ${HOSTS} ; do
ssh -l ${USERNAME} ${HOSTNAME} "${SCRIPT}"
done

How to write a script to run without password on a batch of servers?

#!/bin/ksh

HOSTLIST="<LIST OF HOST>"
DELAY=1
print -n Enter Command to process on remote Host -
read CMD
print
exec 4>&1

for HOST in $HOSTLIST ; do


echo "running ${CMD} on ${HOST}:"
ssh -t -t $HOST >&4 2>/dev/null |&
sleep $DELAY
print -p /usr/bin/nohup ${CMD}
sleep $DELAY
print -p exit
wait
echo "${CMD} completed on ${HOST} !"
done

exit 0

#!/bin/bash

CURL=`curl -I https://ws-us.cometchat.io/|grep "HTTP/1.1 200 OK" |wc -l`

TIMESTAMP=`date`

#STATUS=`cat $CURL |grep "HTTP/1.1 200 OK"`


if (test $CURL -ne 0) then

echo "URL WORKING FINE-" $TIMESTAMP > /tmp/url


exit 0
else
echo "URL NOT WORKING-" $TIMESTAMP > /tmp/url
exit 2

done
fi

i=10;
while [ $i -ge 0 ];
do
echo "reverse order number $i"
let i--;
done

if the condition is true till the condition is false it is exit from loop

echo -e "Please provide one value: \c"


read -r c
while [ $i -le 10 ]
do
b='expr $c \* $i'

while []
do
...
...
done

i=5
until [ $i -gt 15 ];
do
echo "number $1"
i=$(( i+1 ))
done

it displays the output until the condition is false.

array=( dog "little cat" bat mouse );


for i in "${array[a]}"
do
echo "it is a $i"
done

You might also like