If it's not on-topic, it's in here.
Post a reply

again a basch script question

Sun Nov 13, 2016 8:45 am

What i do is this:
if lynx -dump -nolist some-http-webpage | grep "$TERM"
then
echo "found $TERM at some-http-webpage
fi

What i would like is to
store the result of lynx -dump in a file
and
if the file is elder than a week, use lynx again
else
grep through the file

thanks.

Re: again a basch script question

Sun Nov 13, 2016 9:03 pm

Redirect the wget output to file, then grep the file for $TERM

Before you do that, use 'find -mtime <whatever a week ago looks like> -name same-file-as-above' and based on the result, either grep the file or wget it and grep it. You can use mtime to find files up to some time in the past or beyond some time in the past. Been awhile since we done this, huh?

Re: again a basch script question

Mon Nov 14, 2016 7:14 am

Lol. Yes, i do remember something with times. But to me anything scripting related has been a while.

In the meantime i ran in a different problem.
This does work
Code:
if lynx -dump -nolist http://main.mepis-deb.org/MX14packages.html | grep "$search_term"
then
FOUND="yes"
printf "$search_term found in community  repo http://main.mepis-deb.org/MX14packages.html \n"
fi

But as it's several repos, i put them in a list, and the result doesn't work anymore:
Code:
code]
repo_list=(
        http://teharris.net/NewPackages.html
        http://main.mepis-deb.org/MX15packages.html
        http://main.mepis-deb.org/MX14packages.html
        )


#----------------------------------------------------------

for i in ${repo_list[*]}
do
#       if echo "$i"
        if lynx -dump -nolist "$i" | grep "$searchterm"
        then
                FOUND="yes"
                printf "\n$searchterm found in $i\n"
        fi
done

Doesn't work mean:
a) it puts all output of lynx on the screen, not only a sucessful grep and
b) it always says "found at ", no matter what

Here are the two complete scripts:
working way:
http://sprunge.us/COIH
not working with array and loop
http://sprunge.us/HYKT

Usage is: sh repo_crawler <searchterm>

Re: again a basch script question

Mon Nov 14, 2016 8:23 pm

I found the problem:
1) variabe declared as search_term
search_term="$1"
and used as searchterm
2)
if lynx -dump -nolist "$i" | grep "$searchterm"

... now back to the file-date voodoo ...

Re: again a basch script question

Mon Nov 14, 2016 10:35 pm

Your github page has been taken over by someone else. I was going to find an example that we worked on together. Anyway...
Code:
# find files in current directory modified more than 30 days ago:
find . -type f -mtime +30

# find files in current directory modified in the last 10 days:
find . -type f -mtime -10


Code:
if find . -name myfile -mtime +7 ; then
    if lynx -blah > myfile ; then
        grep whatever
        print whatever
   fi
else
    grep whatever
    print whatever
fi
Post a reply