Alex Flo
Alex Flo

Reputation: 200

A file executed from crontab returns different results than from command line

I need to run a script from crontab and this has a simple server load check that looks like this:

server_load=$(bash -c '/bin/more /proc/loadavg | 
              /usr/bin/cut -d" " -f1 | /usr/bin/cut -d"." -f1')

If I run the script from command line I get the server load, if I run it from crontab I get a strange and useless result.

I did look for posts with similar issues but nothing from what was suggested helped me solve my issue.

Upvotes: 1

Views: 228

Answers (1)

msw
msw

Reputation: 43487

That whole line could be simplified to:

server_load=`cut -d. -f1 /proc/loadavg`

I suspect that the problems are related to more wanting a terminal and thus emitting terminal control sequences.

Upvotes: 1

Related Questions