bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17637: bug "cut of end-line is skipped"


From: Pádraig Brady
Subject: bug#17637: bug "cut of end-line is skipped"
Date: Thu, 29 May 2014 23:24:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

tag 17637 notabug
close 17637
stop

On 05/29/2014 10:43 PM, rd wrote:
> helo, i'm a bash shell script beginner...
> forgive my poor English, i'd like to contribute to GNU O.S. reporting this 
> suspect bug.
> 
> it was working perfectly the command from
> ubuntu 12.04 LTS after installed "at" using the terminal command apt-get 
> install at
> 
> #################################
>  echo "`atq`" |cut -d$'\n' -f1  | cut -d$'\t' -f1
> #################################
> 
> return the first number job id  from the scheduler atq Job list.
> exaple: 9432 or 9486 or ... 9498
> 
> it was working perfectly the follow routine from my implementation for video 
> surveillance in shell script running like root user:
> ##################################
> ##################################
> #! /bin/sh
> #
> Kill_All_Jobs()
> {
> local Job_Pid=""
> local Done=false
> local Empty=""
> while [ "$Done" = false  ]
> do
>     Job_Pid=""
>     # set first line
>     Job_Pid=$( echo "`atq`" |cut -d$'\n' -f1 )
>     # set first field
>     Job_Pid=$( echo "$Job_Pid" | cut -d$'\t' -f1 )
>     if [ "$Job_Pid" != "$Empty" ]
>     then
>         echo "KILLING JOB $Job_Pid"
>         at -r "$Job_Pid"
>         echo ""
>         sleep 1
>     else
>         Done=true
>     fi
> done
> }
> ##################################
> ##################################
> 
> 
> Now after Upgrade to ubuntu 14.04 LTS
> the command
> #################################
>  echo "`atq`" |cut -d$'\n' -f1  | cut -d$'\t' -f1
> #################################
> give to a different output result!
> example output is
> 
> 94234
> 94356
> 94237
> 
> in the same bash variable..
> i hope mistake, i think the cut of tabulator is done but the cut of end-line 
> is skipped!
> so the result is a set of values that make the routine in loop .. the at -r 
> command can't operate without a correct parameter variable value.
> 
> after some time.. i replaced the routine using a rea-file-line instruction 
> and temporarily solved
> 
> ##################################
> Kill_All_Jobs()
> {
> local Job_Pid=""
> local Done=false
> local Empty=""
> local Temp_location="$VS_ROOT"
> local Temp_name="atq.sh"
> local Tmp_File="$Temp_location$Temp_name"
> local line=""
> while [ "$Done" = false  ]
> do
>     atq > "$Tmp_File"
> 
>     Job_Pid=""
>     line=""
>     while read line
>     do
>         #set first filed
>         Job_Pid=$( echo "$line" | cut -d$'\t' -f1 )
>         echo "line..$line..$Job_Pid.."
>     done < "$Tmp_File"
> 
>     if [ "$Job_Pid" != "$Empty" ]
>     then
>         echo "KILLING JOB ..$Job_Pid.."
>         at -r "$Job_Pid"
>         echo ""
>         sleep 1
>     else
>         Done=true
>     fi
> done
> kill "$Tmp_File"
> }
> 
> 
> ##################################
> good rule of developing is avoid to use files not necessary...
> 
> so i'd like to have reply from the follow questions:
> 1- what is the correct syntax to use cut with atq command to extract the job 
> id?
> 2- the output  from shell commands use the same field separator and line 
> separator?
> 3- there is a standar output format or metod from shell commands?
> 
> thanks regard ... rudy

That change 
http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=51ce0bf8
was made in v8.21 to fix http://bugs.gnu.org/13498

It was made for a good reason, to handle the buffering issues detailed
in the above bug. Your existing usage was a bit of an edge case and not
supported with other cut implementations, and while we try to avoid
changes like this it was thought the benefits outweighed the impact
for the very few who use cut in this way.

There are many more standard ways to achieve what you want.
Here are two that come to mind immediately:

  job_pid=$(atq | head -n1 | cut -f1)
  job_pid=$(atq | sed 's/[^0-9].*//;q')

thanks,
Pádraig.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]