# Lynx + Cron



## czeri (Aug 25, 2016)

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.


```
#!/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:

```
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 ; ;
```


----------



## tobik@ (Aug 25, 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):

```
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
```
 or change your script to use the absolute path to lynx: 
	
	



```
#!/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
```


----------



## czeri (Aug 25, 2016)

tobik said:


> /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):
> 
> ```
> PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
> ...




I changed it, but did not help


----------



## czeri (Aug 25, 2016)

My mistakes, It works.
I did not notice an entry

```
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


----------



## SirDice (Aug 25, 2016)

Why don't you use fetch(1)? It's available by default, lynx isn't.


----------



## tobik@ (Aug 25, 2016)

SirDice said:


> 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 `fetch`ing it.

But even then a better answer to parsing HTML is probably Python with html5lib or something similar.


----------



## czeri (Aug 25, 2016)

SirDice said:


> Why don't you use fetch(1)? It's available by default, lynx isn't.



Because fetch shows web page with html code and dificult is show specific data.


----------



## SirDice (Aug 25, 2016)

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.


----------

