-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuntardir.sh
62 lines (54 loc) · 2.21 KB
/
untardir.sh
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/QOpenSys/pkgs/bin/bash
#----------------------------------------------------------------
# Script name: untardir.sh
# Author: Richard Schoen
# Parameters:
# 1.) File name to unzip and unarchive with tar. Can also use a partial wildcard.
# Files and dirs are extracted to the same dir where the .tar.gz file is located.
#
# Purpose: Extract all files and subdirs from
# a .tar.gz file to current directory
#
# Result:
# All files should be extracted and listed to STDOUT console log as well.
# Exits:
# 0=Normal - No errors.
# Non-zero - Errors occuured.
#
# Useful links:
# https://www.linuxquestions.org/questions/linux-newbie-8/tar-all-files-and-folders-in-the-current-directory-4175487694/
# https://superuser.com/questions/418704/7-zip-command-line-to-zip-all-the-content-of-a-folder-without-zipping-the-folde
#----------------------------------------------------------------
function error_exit
{
# ----------------------------------------------------------------
# Function for exit due to fatal program error
# Accepts 1 argument: string containing descriptive error message
# ----------------------------------------------------------------
#echo "//-----------------------------------------------------------"
echo "ERROR: ${SCRIPTNAME}: ${1:-"Unknown Error"}" 1>&2
#echo "//-----------------------------------------------------------"
exit 1
}
# Make sure our arguments are passed
if [ $# -lt 1 ]
then
error_exit "ERROR: Missing parameters. P1-File name must be specified. Process cancelled."
fi
# Set date/time variables
DATESTAMP=$(date +%Y%m%d)
TIMESTAMP=$(date +%H%M%S)
EPOCHVALUE=$(date "+%s")
EPOCHFIRST10="T${EPOCHVALUE:0:10}"
EPOCHFIRST9="T${EPOCHVALUE:0:9}"
EPOCHFIRST6="T${EPOCHVALUE:0:6}"
# https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash
# Set output file from passed file prefix.
# Output file will be unique timestamped.
OUTPUTFILE=$1
# Tar and gzip files in selected current directory to tar file.
# Tar file named based on passed in prefix + timestamp.tar.gz
# Use . to archive all files, including hidden ones.
# Note: Could change to * to archive all files, and skip hidden ones.
tar -xvf ${OUTPUTFILE}
echo "Files unarchived from ${OUTPUTFILE}"