Hello all-
Having a long day and need help with the following basic function.
I would like to achieve is to run this in a directory and unzip all gzip files and exit.
What I
don't want is for you to write the script for me, just a hint.
What happens when I run the script in my home directory it works and I get good results.
However, when I run this in a directory where the files actually live I get the following error:
Code:
find: paths must precede expression: antimalware.errors1103190003.log.gz
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Code:
#!/bin/bash
# Will unzip all gzip files in current working directory with any of the following options.
AM="*antimalware*.gz"
PWD=`pwd`
echo ""
echo "Please select one of the followin options to unzip the following log files in your current working directory"
echo ""
echo "1: Antimalware"
echo "2: Coordinator"
echo "3: Core"
echo "4: Log manager"
echo "5: Sysconfig"
echo "6: User Interface"
echo ""
antimal () {
for p in $PWD; do
find $p -type f -name $AM
done
}
read number
#for i in `ls -X`; do
# gzip -d $i
#done
if [[ $number == 1 ]]; then
antimal;
elif [[ $number == 2 ]]; then
$PWD
elif [[ $number == 3 ]]; then
$PWD
elif [[ $number == 4 ]]; then
$PWD
elif [[ $number == 5 ]]; then
$PWD
elif [[ $number == 6 ]]; then
$PWD
fi
Update:Ok, I don't know what I was thinking, but I think I fixed this with the following modification:
Code:
antimal () {
for i in $AM;do
gzip -d $i
done
}
Update:So I have this working script now. I just feel like its too bloated and its ofcourse only a beginer script.
Can someone please help me streamline my script. I want to be able to have only one fuction that can take my selected option and give me results based on my selection; again, without all those cluttered functions.
Code:
#!/bin/bash
# Will unzip all gzip files in current working directory with any of the following options.
AM="*antimalware*.gz"
COO="*coordinator*.gz"
COR="*core*.gz"
LOG="*log*.gz"
SYS="*sysconfig*.gz"
UI="*ui*.gz"
echo ""
echo "Please select one of the followin options to unzip the following log files in your current working directory:"
echo ""
echo "1: Antimalware"
echo "2: Coordinator"
echo "3: Core"
echo "4: Log manager"
echo "5: Sysconfig"
echo "6: User Interface"
echo ""
# Functions
antimal () {
for a in $AM;do
gzip -d $a
done
}
coord () {
for c in $COO;do
gzip -d $c
done
}
cor () {
for co in $COR;do
gzip -d $co
done
}
log () {
for l in $LOG;do
gzip -d $l
done
}
sys () {
for s in $SYS;do
gzip -d $s
done
}
useri () {
for u in $UI;do
gzip -d $u
done
}
# Script
read number
if [[ $number == 1 ]]; then
antimal;
elif [[ $number == 2 ]]; then
coord;
elif [[ $number == 3 ]]; then
cor;
elif [[ $number == 4 ]]; then
log;
elif [[ $number == 5 ]]; then
sys;
elif [[ $number == 6 ]]; then
useri;
fi