DEV Community

Alexandru Bucur
Alexandru Bucur

Posted on

ps aux output in cronjobs

Hello there,

Going trough an ad-hoc cronjob for checking an existing process I've hit a weird case that the command itself was working well when ran from the terminal, but failed miserabely when the cronjob ran it.

The command was something along the lines of:

ps aux | grep 'php artisan a_specific_command --with-some-long-parameters-that were generated' | grep -v grep
Enter fullscreen mode Exit fullscreen mode

The thing that I've completely forgotten is that by default ps's output is limited by the number of $COLUMNS. As a standard that's set to 80 chars (that of course you can easily change).

Because of that, the output line itself was truncated when ran trough the cron command (and worked well on my full hd screen that has aproximately 171 columns, you can test yourself by using echo $COLUMNS).

The easiest solution for fixing this is using the Wide output mode twice for unlimited width

ps auxww | grep 'php artisan a_specific_command --with-some-long-parameters-that were generated' | grep -v grep
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
tadman profile image
Scott Tadman

The little known -o option also allows you to customize the output columns to fit your needs better.

man7.org/linux/man-pages/man1/ps.1...

Collapse
 
ferricoxide profile image
Thomas H Jones II

Dammit: beat me to it.

A lot of commands have output-formatter options. Life-savers when you don't want to have to write complex output-filters or when you want more-predictable or useful output.

And, where commands don't have output-formatters, they often have analogous tools that provide similar output-types but in more-useful (for the use-case) outputs.