I'm trying this:
token=`curl -I --header "X-Auth-User: [email protected]" --header "X-Auth-Key: XXXXXXXXXXXXXXXXXXXXXX" api.server.com | grep -Fi X-Auth-Token | awk -F" " '{ print $2}'` /usr/bin/wget --accept .jpg,.jpeg -p "https://api.server.com/v1/stats/1/graph?callback=jQuery171027000000144289315_1380000003353&mnum=1&res_type=cpu&g_type=6h&graph_type=img&full=1&w=515&h=150&X-Auth-Token=$token" -O "image.jpg" || rm "image.jpg"
But my token result is:
https://api.server.com/v1/stats/1/graph?callback=jQuery171027000000144289315_1380000003353&mnum=1&res_type=cpu&g_type=6h&graph_type=img&full=1&w=515&h=150&X-Auth-Token=SERVER_018d8100000000001d1b817f7d58a6%0D
Instead of:
https://api.server.com/v1/stats/1/graph?callback=jQuery171027000000144289315_1380000003353&mnum=1&res_type=cpu&g_type=6h&graph_type=img&full=1&w=515&h=150&X-Auth-Token=SERVER_018d8100000000001d1b817f7d58a6
How to remove %0D (Carriage return)?
To remove the last n characters of a string, we can use the parameter expansion syntax ${str::-n} in the Bash shell. -n is the number of characters we need to remove from the end of a string.
A simple and elegant answer from Stripping single and double quotes in a string using bash / standard Linux commands only: BAR=$(eval echo $BAR) strips quotes from BAR . If you don't want anything printed out, you can pipe the evals to /dev/null 2>&1 .
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
Use sed 's/^ *//g', to remove the leading white spaces. There is another way to remove whitespaces using `sed` command. The following commands removed the spaces from the variable, $Var by using `sed` command and [[:space:]]. $ echo "$Var are very popular now."
You can add | tr -d '\r'
to your curl pipeline to strip any carriage returns.
There is a utility called dos2unix. You may have to install it. or use the translate
tr -d '\r' < input > output
EDIT Found a post that discusses a few options: Remove carriage return in Unix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With