w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
python regex doesnt match when run from cron

What you're seeing there is termcap codes for displaying things based on the kind of display device connected. When you run that command from cron, there is no connected device. Your program isn't giving you the same data.

Here are three possible ways to get the same data:

1) Maybe, you can set the terminal environment variable and your program might (!!) work the same. It not very likely. In cron "TERM=vt100OrSomething /pathtomyscript/myscript.py" . No "export" or semicolon or anything.

2) You could run it detached inside screen or tmux, and use their terminal emulation. Or, you could use Expect's "unbuffer" program. You'll have to change your code to match what it sends for tmux's fake termainal.

3) Connect normally, and unset your "TERM" env variable, and then you'll be a lot like the cron environment. Don't try to make the crazy, unknown cron environment like your interactive session is. Make your interactive session like your cron environment is, and solve it there.

Of all these, I think you should go with #3. Start sub-shells to test:

$ vi program    
$ bash    
$ unset TERM; PS1=$$    
$$ ./program    
$$ exit    
$ vi program    
...




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.