sunhux
asked on
Help troubleshoot a Shell script
nohup ./globscan.sh 2> /tmp/glo.err &
When I run the attached script, it gave an error message below:
# more /tmp/glo*err*
Sending output to nohup.out
/opt/uvscan/globscan.sh: [[: not found
/opt/uvscan/globscan.sh: syntax error at line 4: `(' unexpected
# more nohup.out
/opt/uvscan/globscan.sh: [[: not found
/opt/uvscan/globscan.sh: syntax error at line 4: `(' unexpected
./globscan.sh: [[: not found
./globscan.sh: syntax error at line 4: `(' unexpected
If I run it as follows, don't get any error:
ksh -v /opt/globscan.sh
The permission of the script file is 755
What did I miss? All lines end with <LF> as I checked using "cat -ev ..." or vi's set line on
When I run the attached script, it gave an error message below:
# more /tmp/glo*err*
Sending output to nohup.out
/opt/uvscan/globscan.sh: [[: not found
/opt/uvscan/globscan.sh: syntax error at line 4: `(' unexpected
# more nohup.out
/opt/uvscan/globscan.sh: [[: not found
/opt/uvscan/globscan.sh: syntax error at line 4: `(' unexpected
./globscan.sh: [[: not found
./globscan.sh: syntax error at line 4: `(' unexpected
If I run it as follows, don't get any error:
ksh -v /opt/globscan.sh
The permission of the script file is 755
What did I miss? All lines end with <LF> as I checked using "cat -ev ..." or vi's set line on
ASKER
Typo:
If I run it as follows, don't get any error:
ksh -v /opt/avscan/globscan.sh
OR
/opt/avscan/globscan.sh
Am using root in all cases
If I run it as follows, don't get any error:
ksh -v /opt/avscan/globscan.sh
OR
/opt/avscan/globscan.sh
Am using root in all cases
ASKER
I tot it's due to the "For" which I've just changed to "for" in line 3 but still giving the same error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Simon; I've seen cases where the following housekeeping command fails with a
message "argument list too long" :
rm `find /var/*.log -print`
I'll test it out tomorrow. There's a possibility one of those 500 Solaris/Unix servers has
millions of files in it
message "argument list too long" :
rm `find /var/*.log -print`
I'll test it out tomorrow. There's a possibility one of those 500 Solaris/Unix servers has
millions of files in it
ASKER
Btw, does the latest script you've amended with "fc ..." work
for both Bash & Korn shells? There's a chance we may use
Bourne (ie /bin/sh) but unlikely. Nobody uses C-shell here
for both Bash & Korn shells? There's a chance we may use
Bourne (ie /bin/sh) but unlikely. Nobody uses C-shell here
ASKER
So I won't need the "var=0" anymore or if it's still needed, we'll need to increment it for every file scanned:
((var=var+1))
((var=var+1))
If the script has the #! line as the first line in the file, it will use that specified shell whatever the caller is using (even if they use csh).. That said, the "[ ]" version should work with most non-c shells, as will.my bit of code.
You don't need the $var variable at all. The problem here is that because the while loop is in a pipeline (it takes its input from the output of another command), any variables you change within the loop do not affect the value outside the loop. So, you'd set var to 0 at the beginning and increment it inside the loop, but after the loop, the value would still be 0. I worked round this by adding the processed file names, one name per line, to a file. After the loop, the number of lines in the file gives the number of files processed.
You don't need the $var variable at all. The problem here is that because the while loop is in a pipeline (it takes its input from the output of another command), any variables you change within the loop do not affect the value outside the loop. So, you'd set var to 0 at the beginning and increment it inside the loop, but after the loop, the value would still be 0. I worked round this by adding the processed file names, one name per line, to a file. After the loop, the number of lines in the file gives the number of files processed.
ASKER
Think there's a little syntax error in the last script:
-bash-3.2# nohup nice ./globscan.sh 2> /tmp/glo.err
-bash-3.2#
-bash-3.2# more /tmp/glo.err
Sending output to nohup.out
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
-bash-3.2# nohup nice ./globscan.sh 2> /tmp/glo.err
-bash-3.2#
-bash-3.2# more /tmp/glo.err
Sending output to nohup.out
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
ASKER
Think it lies on this line:
find /* -type f -size -52428800c | grep -v -f grepv.ctl | while read scanfile; do
find /* -type f -size -52428800c | grep -v -f grepv.ctl | while read scanfile; do
ASKER
or was it intended to be
grep -v -F grepv.ctl
grep -v -F grepv.ctl
ASKER
or it was meant to be:
grep -v -F=grepv.ctl
grep -v -F=grepv.ctl
ASKER
Sorry the last post has a typo ie should read
or it was meant to be:
grep -v -f=grepv.ctl
or it was meant to be:
grep -v -f=grepv.ctl
ASKER
The following gave the same error:
grep -v -f=grepv.ctl
grep -v -f=grepv.ctl
ASKER
http://unix.stackexchange.com/questions/83260/reading-grep-patterns-from-a-file
Also tried "grep -F -f grepv.ctl" & it gave the same error
with just "grep -f grepv.ctl" (ie with -v removed), still gave same error
Also tried "grep -F -f grepv.ctl" & it gave the same error
with just "grep -f grepv.ctl" (ie with -v removed), still gave same error
ASKER
http://stackoverflow.com/questions/4024637/passing-a-file-with-multiple-patterns-to-grep
Not quite sure how I can implement the above with the syntax below:
tr -d "\r" <match.txt | grep -F -f - text.txt
Not quite sure how I can implement the above with the syntax below:
tr -d "\r" <match.txt | grep -F -f - text.txt
ASKER
so the "-v" is supposed to be there, right? It's to grep lines "not" containing the pattern in grepv.ctl
So I've amended grep to fgrep ie:
find /* -type f -size -52428800c | fgrep -v -f grepv.ctl | while read scanfile; do
Is the above correct? So far, it did not complaint
So I've amended grep to fgrep ie:
find /* -type f -size -52428800c | fgrep -v -f grepv.ctl | while read scanfile; do
Is the above correct? So far, it did not complaint
ASKER
With the above syntax, I just noticed it scanned Oracle... folder which I don't
want it to (as supposed to exclude "[Oo]racle" in grepv.ctl)
root 23079 20392 1 20:02:02 pts/2 0:01 ./vscan -p=/opt/uvscan /Oracle11g/doc/owb.112/e17 130/img_te xt/exporti ng_
What did I miss?
want it to (as supposed to exclude "[Oo]racle" in grepv.ctl)
root 23079 20392 1 20:02:02 pts/2 0:01 ./vscan -p=/opt/uvscan /Oracle11g/doc/owb.112/e17
What did I miss?
ASKER
Just spotted it scans "/boot" which it was not supposed to:
... pts/2 0:01 ./vscan -p=/opt/uvscan /boot/grub/menu.lst -NC -l=/opt/uvscan /tmp/scan
... pts/2 0:01 ./vscan -p=/opt/uvscan /boot/grub/menu.lst -NC -l=/opt/uvscan /tmp/scan
ASKER
Looks like, we'll need to remove those "beginning", "Containing", "ending" characters ie
^
\
[ ]
^
\
[ ]
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm on Solaris 10 x86 (64bit). By removing the
^ \ [] characters & using "fgrep", got it going.
I'm not at liberty to install any packages/software
on the Solaris x86 VMs as they belong to our
tenants.
Found that the scan takes rather long & I'm now exploring
how I can optimize the coding : thought "ls ..." command is
faster than "find ..." command, so is the code below faster:
Change
find /* -type f -size -52428800c | grep -v -f grepv.ctl | while read scanfile; do
cd /
ls -aR -type f -size -52428800c | grep -v -f grepv.ctl | while read scanfile; do
(am assuming ls has the -type & -size options). Back home now, so can't
test out the above code
^ \ [] characters & using "fgrep", got it going.
I'm not at liberty to install any packages/software
on the Solaris x86 VMs as they belong to our
tenants.
Found that the scan takes rather long & I'm now exploring
how I can optimize the coding : thought "ls ..." command is
faster than "find ..." command, so is the code below faster:
Change
find /* -type f -size -52428800c | grep -v -f grepv.ctl | while read scanfile; do
cd /
ls -aR -type f -size -52428800c | grep -v -f grepv.ctl | while read scanfile; do
(am assuming ls has the -type & -size options). Back home now, so can't
test out the above code
ASKER
>tried egrep instead?
Haven't got a chance to try egrep, what's the syntax like?
Haven't got a chance to try egrep, what's the syntax like?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
egrep syntax is basically the same as grep and fgrep - it just supports extended regular expressions such as "abc|xyz" to look for "abc" or "xyz".
ASKER
I just realized that this "find ..." coding for AV scanner to do the scan is not efficient because:
for each files to be scanned, the scanner will open the signature pattern file, library etc.
If we feed the folders' names to this scanner don't need to suffer this long scan timings
for each files to be scanned, the scanner will open the signature pattern file, library etc.
If we feed the folders' names to this scanner don't need to suffer this long scan timings
Does vscan6 work on files or directories? I assumed files, because of the way you wrote the original script.
If so, you could use xargs to supply multiple file names:
find /* -type f | /usr/bin/xpg4/bin/grep -v -f grepv.ctl | xargs. /vscan6.. .. .. ..
Add the -size and vscan6 parameters as necessary (I'm on my phone at the moment, so cut and paste is hard!)
This will work as long as you can have a series of file names at the end of vscan6 command (I.e. you don't use $scanfile, but instead just have names of files to scan at the end of the command). If not, we'll have to rethink, snd I'll ned to be at my computer!
If so, you could use xargs to supply multiple file names:
find /* -type f | /usr/bin/xpg4/bin/grep -v -f grepv.ctl | xargs. /vscan6.. .. .. ..
Add the -size and vscan6 parameters as necessary (I'm on my phone at the moment, so cut and paste is hard!)
This will work as long as you can have a series of file names at the end of vscan6 command (I.e. you don't use $scanfile, but instead just have names of files to scan at the end of the command). If not, we'll have to rethink, snd I'll ned to be at my computer!
ASKER
This vscan6 could take in files as well as directories: unfortunately, it's much more
efficient if it take in a folder rather than a list of files under that folder because if
it take a list of files, it will read the signature pattern file plus a library file the number
of time as the number of files.
So if /usr has 9000 files, vscan6 will read the pattern+library files plus output a banner
to a logfile 9000 times ie each time before it scan a file, it will read the pattern & library
& after scanning that file, it will output a banner.
if it's given a folder, it only reads the pattern+library files once tho there's 9000 files
in usr.
As this is now a radically new requirement, will most appreciate if you can look at
it at the new question that I've raised:
https://www.experts-exchange.com/questions/28703371/Need-Shell-script-to-parse-thru-suitable-filesystems-files-folders-for-AV-scanning.html
efficient if it take in a folder rather than a list of files under that folder because if
it take a list of files, it will read the signature pattern file plus a library file the number
of time as the number of files.
So if /usr has 9000 files, vscan6 will read the pattern+library files plus output a banner
to a logfile 9000 times ie each time before it scan a file, it will read the pattern & library
& after scanning that file, it will output a banner.
if it's given a folder, it only reads the pattern+library files once tho there's 9000 files
in usr.
As this is now a radically new requirement, will most appreciate if you can look at
it at the new question that I've raised:
https://www.experts-exchange.com/questions/28703371/Need-Shell-script-to-parse-thru-suitable-filesystems-files-folders-for-AV-scanning.html
ASKER
Avscan-errScript.txt