Problem with "head -n 1" when using /dev/urandom
search cancel

Problem with "head -n 1" when using /dev/urandom

book

Article ID: 218346

calendar_today

Updated On:

Products

CA Automic One Automation

Issue/Introduction

Problem with "head -n 1" when using /dev/urandom within function during Unix Job execution.

The issue was reproduced with below line.

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 13 | head -n 1

Environment

Release : 12.2, 12.3

Component : AUTOMATION ENGINE

Sub-Component: Linux Agent

Cause

This problem is related to the feature of linux where program "head -n 1" ends, but the rest ignores the signal because they are running in an non-interactive shell. More information can be found here: https://stackoverflow.com/questions/26461014/bash-head-tail-behavior-with-bash-script

Resolution

The workaround is to change/rearrange your script that it could use below example:

1. The issue was reproduced with below line:

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 13 | head -n 1

To go around this we created a shell script random.sh with the following content:

#!/bin/bash

{ head -n 1; kill "$!"; }< <(exec cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 13)

2. Another workaround is to use an older agent, from 12.0 - the last SP preferred.

Additional Information

Fix planned in future releases, no date known yet