Lynx + Cron

Hello I have problem with script lynx + cron. We would like search something every minute and save to file.
If I run script without cron every work fine but if scrip run by cron the file is empty.

Code:
#!/bin/sh

data=` date | cut -d ' ' -f2-4 -f6`


hasp3_physical=`lynx -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f6`
hasp4_physical=`lynx -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f9`

echo $data ";" $hasp3_physical ";" $hasp4_physical >> /home/info.txt

After run script with cron the file info.txt contains only date:
Code:
Aug 24 23:25:00 2016 ; ;
Aug 24 23:25:00 2016 ; ;
Aug 24 23:25:00 2016 ; ;
Aug 24 23:26:00 2016 ; ;
Aug 24 23:26:00 2016 ; ;
Aug 24 23:26:00 2016 ; ;
Aug 24 23:27:00 2016 ; ;
Aug 24 23:27:00 2016 ; ;
Aug 24 23:27:00 2016 ; ;
Aug 24 23:28:00 2016 ; ;
Aug 24 23:28:00 2016 ; ;
Aug 24 23:28:00 2016 ; ;
Aug 24 23:29:00 2016 ; ;
Aug 24 23:29:00 2016 ; ;
 
/usr/local/bin is not in the PATH of cron scripts by default. You're going to have to add this to the top of your crontab(5):
Code:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
or change your script to use the absolute path to lynx:
Code:
#!/bin/sh
LYNX=/usr/local/bin/lynx

data=` date | cut -d ' ' -f2-4 -f6`


hasp3_physical=`${LYNX} -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f6`
hasp4_physical=`${LYNX} -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f9`

echo $data ";" $hasp3_physical ";" $hasp4_physical >> /home/info.txt
 
/usr/local/bin is not in the PATH of cron scripts by default. You're going to have to add this to the top of your crontab(5):
Code:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
or change your script to use the absolute path to lynx:
Code:
#!/bin/sh
LYNX=/usr/local/bin/lynx

data=` date | cut -d ' ' -f2-4 -f6`


hasp3_physical=`${LYNX} -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f6`
hasp4_physical=`${LYNX} -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f9`

echo $data ";" $hasp3_physical ";" $hasp4_physical >> /home/info.txt


I changed it, but did not help
 
My mistakes, It works.
I did not notice an entry
Code:
LYNX=/usr/local/bin/lynx

data=` date | cut -d ' ' -f2-4 -f6`


hasp3_physical=`${LYNX} -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f6`
hasp4_physical=`${LYNX} -dump http://web-page | grep Kasa | grep Handel  | cut -d ' ' -f9`

Thank you :)
 
Why don't you use fetch(1)? It's available by default, lynx isn't.
lynx -dump outputs a rendered plain text representation of a web page. It's not equivalent to just fetching it.

But even then a better answer to parsing HTML is probably Python with html5lib or something similar.
 
Ah, that I understand. If possible I'd make some changes to the website itself though. I'd save the data as a JSON file and have the page dynamically created based on the info in the JSON. Then you could simply fetch that JSON file. Or, if it's already a dynamic page, add some logic to export just the data. That'll make things like this easier to do.
 
Back
Top