0

Below is the output command when i execute im getting multiple line.

My question is that i should want to have multiple line instead of that a single line is need in script

Output command:- bash script.sh --username USERNAME --password PASSWORD --project "Test Project"

oxNjM5ODA2MTg5fQ.ea82ZkR5afv5uT0m6l8ttutOWCelPlxuyr4iU3VkZyU
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9617    0  9617    0     0   7166      0 --:--:--  0:00:01 --:--:--  7160
runId = 8a8094017dbc2780017dc6ea6a3c0780
taskStatus =  WAITING
Checking Status....
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9725    0  9725    0     0   7209      0 --:--:--  0:00:01 --:--:--  7214
Status = PROCESSING  Success Percent = 100.0  Total Tests = 75  Total Failed = 0  Run = 16
Checking Status....
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9725    0  9725    0     0   7155      0 --:--:--  0:00:01 --:--:--  7155
Status = PROCESSING  Success Percent = 100.0  Total Tests = 75  Total Failed = 0  Run = 16
Checking Status....
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9862    0  9862    0     0   7465      0 --:--:--  0:00:01 --:--:--  7465
Status = PROCESSING  Success Percent = 93.0  Total Tests = 75  Total Failed = 5  Run = 16
Checking Status....
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9862    0  9862    0     0   7493      0 --:--:--  0:00:01 --:--:--  7493
Status = PROCESSING  Success Percent = 93.0  Total Tests = 75  Total Failed = 5  Run = 16
Checking Status....
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9886    0  9886    0     0   7517      0 --:--:--  0:00:01 --:--:--  7517
Status = COMPLETED  Success Percent = 90.0  Total Tests = 75  Total Failed = 7  Run = 16

And Here is my shellscript

#!/bin/bash
# Begin
TEMP=$(getopt -n "$0" -a -l "username:,password:" -- -- "$@")

    [ $? -eq 0 ] || exit

    eval set --  "$TEMP"

    while [ $# -gt 0 ]
    do
             case "$1" in
                    --username) TS_USER="$2"; shift;;
                    --password) TS_PWD="$2"; shift;;
                    --) shift;;
             esac
             shift;
    done


curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${TS_USER}'", "password": "'${TS_PWD}'"}' https://example.com/login

echo "generated token is:" $token

curl --location --request POST "https://example.com/" --header "Authorization: Bearer "$token"" 

echo "runId =" $runId

if [ -z "$runId" ]
then
          echo "RunId = " "$runId"
          echo "Invalid runid"
          echo $(curl --location --request POST "https://example.com/" --header "Authorization: Bearer "$token"")
          exit 1
fi


taskStatus="WAITING"
echo "taskStatus = " $taskStatus



while [ "$taskStatus" == "WAITING" -o "$taskStatus" == "PROCESSING" ]
         do
                sleep 5
                 echo "Checking Status...."

                passPercent=$(curl --location --request GET "https://example.com/" --header "Authorization: Bearer "$token"")

                    

                        taskStatus="${array[0]}"

                        echo "Status =" "${array[0]}" " Success Percent =" "${array[1]}"  " Total Tests =" "${array[2]}" " Total Failed =" "${array[3]}"



                if [ "$taskStatus" == "COMPLETED" ];then
            echo "------------------------------------------------"
                       
                        echo  "Run detail link https://example.com${array[7]}"
                        echo "-----------------------------------------------"
                        echo "Job run successfully completed"
                        exit 0

                fi
        done

 
echo "Task Status = " $taskStatus
 exit 1
fi

echo "$(curl --location --request GET "https://example.com/" --header "Authorization: Bearer "$token"")"
exit 1

return 0

Just want single line what i need to add in above script so that it should show only one line i.e, Status.... Status = COMPLETED Success Percent = 90.0 Total Tests = 75 Total Failed = 7 Run = 16

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Mohd Rashid
  • 101
  • 2
  • 9
  • Are you asking how to turn off curl's progress logs? (the man page answers that). And why do you call curl more than once if there should be only one line of output? – Charles Duffy Dec 17 '21 at 12:28
  • yes that only my required – Mohd Rashid Dec 17 '21 at 13:30
  • Then just take out the first two `curl`s entirely, and use `-s` on the third one. Or add `-s` to all three if you really need the first two for some other reason, but redirect the output of the first two so it isn't shown to the user. – Charles Duffy Dec 17 '21 at 14:26
  • Also, this is mostly duplicative of [How do I get curl to not show the progress bar?](https://stackoverflow.com/questions/7373752/how-do-i-get-curl-to-not-show-the-progress-bar) – Charles Duffy Dec 17 '21 at 14:26
  • To be clear, `somecommand` runs somecommand _with its output to stdout_. You don't need to write `echo $(somecommand)` to make its output be written, because output is _always_ written unless you actively do something (like add `>/dev/null`) to turn that off. And `echo $(somecommand)` is also buggy in the ways described in [I just assigned a variable, but `echo $variable` shows something else!](https://stackoverflow.com/questions/29378566). – Charles Duffy Dec 17 '21 at 14:28
  • If you want to replace newlines with spaces, consider piping to `tr '\n' ' '` as a way to do that with fewer unwanted side effects. – Charles Duffy Dec 17 '21 at 14:47

1 Answers1

0

Using curl's -s or --silent parameter, you make sure that curl operates in silent or quiet mode. Note that error messages will also be hidden from you.

man curl will show you all available options to the command.

aTEraGOU
  • 1
  • 1
  • by adding -s i got below 3 lines Checking Status.... Status = PROCESSING Success Percent = 100.0 Total Tests = 75 Total Failed = 0 Run = 17 Checking Status.... Status = PROCESSING Success Percent = 100.0 Total Tests = 75 Total Failed = 0 Run = 17 Checking Status.... Status = COMPLETED Success Percent = 90.0 Total Tests = 75 Total Failed = 7 Run = 17 as i said i need only 1 single line to be show – Mohd Rashid Dec 17 '21 at 13:31
  • @user17201361, comments don't preserve line endings so your comment doesn't tell us anything about how many lines of output you still have. – Charles Duffy Dec 17 '21 at 14:25
  • If this is what the user was asking for, the question should be closed as a duplicate of [How do I get curl to not show the progress bar?](https://stackoverflow.com/questions/7373752) instead of being answered. See the _Answer Well-Asked Questions_ section of [How to Answer](https://stackoverflow.com/help/how-to-answer). – Charles Duffy Dec 17 '21 at 14:30
  • @CharlesDuffy 3 output of lines im getting and about the link which u have send above is different to my case i have already add -s in curl but still im getting 3 lines of output – Mohd Rashid Dec 17 '21 at 14:41
  • And what part of your code makes you think it _shouldn't_ emit three separate lines of output? `-s` just tells curl not to print extra status; it doesn't stop it from printing newlines when the server sends them. – Charles Duffy Dec 17 '21 at 14:46
  • and also in script in curl is begins use 5 times but output got 3 times that means 2 times skip i want to skip remaining 2 curl so that only 1 curl begins used in output – Mohd Rashid Dec 17 '21 at 15:10