The bash scripts below is usefull as template starter script.

Total time script

Script to calculate total execution time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/ksh

# Assign value for start and end time
start_time=$(date +'%Y-%m-%d %H:%M:%S')

#--- Simulating a task taking 15 sec ---
sleep 15 

end_time=$(date +'%Y-%m-%d %H:%M:%S')

start_timestamp=$(date -d "$start_time" '+%s')
end_timestamp=$(date -d "$end_time" '+%s')

# Calculate the time difference in seconds
time_diff=$((end_timestamp - start_timestamp))

# Display time in readable format hours:minutes:seconds
total_time=$(date -u -d@"$time_diff" +'%H:%M:%S')
echo "Total time : $total_time"

Oracle Data pump export script

Show start, stop and total time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/ksh
# SHELL SCRIPT FOR DATA PUMP EXPORT SCHEMA APPL01
#
# Author : Tommy Roennholm
#
# " nohup ./Expdp_FREEPDB1_APPL01.sh > Expdp_FREEPDB1_APPL01_20250321-1.txt 2>&1 & "
#
start_time=$(date +'%Y-%m-%d %H:%M:%S')
start_timestamp=$(date -d "$start_time" '+%s')

echo "Start Time : $start_time"
echo "============================================"

expdp system/@*******@FREEPDB1 parfile=Expdp_FREEPDB1_APPL01.par
RC=$?

end_time=$(date +'%Y-%m-%d %H:%M:%S')
end_timestamp=$(date -d "$end_time" '+%s')

time_diff=$((end_timestamp - start_timestamp))
total_time=$(date -u -d@"$time_diff" +'%H:%M:%S')

echo "RC=$RC"
echo "============================================"
echo "End Time   : $end_time"
echo "TOTAL TIME : $total_time"

bash script using local declaration

Exampel of function with local variable declaration.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/bin/bash

my_var="global value"

my_function() {
    local my_var="Local value"   # Create local varible
    echo "In function my_fuction() my_var = $my_var"
}

my_function
echo "Outside function my_var = $my_var"   # Display "global value", the globala variabeln remain unchange.