0

I have a script renaming a file due to the configuration. By what it s renaming file on $last - its adding a space, so the program not working correctly. What can be the problem?

Config file https://configmaker.com/my/TintedRawRubberyChafer.txt

Code

#!/bin/bash

while true 
    do 

    wget https://configmaker.com/my/TintedRawRubberyChafer.txt

    source TintedRawRubberyChafer.txt

    if [-e $curr]; then
        echo "Make changes"
        mv claymore.stub.conf $last
        mv $curr claymore.stub.conf
    fi

    rm TintedRawRubberyChafer.txt | echo "removed"

    sleep 60

done

exit 0

The thing is, the output from console is 'claymore.stub.conf' -> 'zcash'$'\r'. But there must not be '\r'

  • I'd never heard of configmaker.com before now. I feel ill seeing just how far the terrible idea of "download arbitrary text from the internet and execute it without care" has spread. python and ruby and node.js developers (amongst others) have a LOT to answer for and better not be standing near any walls when the revolution comes. Security First! viva la revolución! – cas Jul 29 '17 at 05:48
  • @cas Man, that script must be executed on 158 mining farm. Which are based on EthOs. Whose free memory are 50-60 megabytes. And they should work on 100% for making money. Second. They all are in local server. And the last. The guys who created EthOs ARE USING CONFIGMAKER. This is their on web-site. And you can control 158 servers using this. So what would you say? – Zhyhalo Oleksandr Jul 29 '17 at 07:00
  • I'd say that telling people to download text and execute it is still stupid, irresponsible, and just plain wrong, no matter what the purpose. It teaches and encourages extremely dangerous habits. Provide the damn variables in some easily parsable format that doesn't require execution. json, for example. – cas Jul 29 '17 at 07:34
  • if you don't understand my point imagine what would happen to your ecoin mining setup if someone hacked that configmaker.com page and added "rm -rf /" to the downloadable "config". or code that looked for your secret keys or coin wallet and mailed them to somewhere. – cas Jul 29 '17 at 07:37
  • BTW, it's not necessary to execute the text that is downloaded. It's in a fairly parsable format (key=value) so it would be quite easy to sanity-check and parse it and extract the values and assign them to the right variables. and abort if there's anything even remotely suspicious in the file (i.e. it looks different to what you're expecting). – cas Jul 29 '17 at 07:40
  • @cas if someone will type rm -ft /* it will just check if exist such file in home directory. – Zhyhalo Oleksandr Jul 29 '17 at 11:00
  • No. That is completely incorrect. When you tell bash (or sh etc) to source a file, you are telling it to read and execute the contents in the current shell process - it's the sh equivalent of include. If that file contains rm -rf / then the shell will proceed to delete everything that the user running it has permission to delete. It will execute whatever is in that file. – cas Jul 29 '17 at 11:54
  • @cas how can i improve that? – Zhyhalo Oleksandr Jul 29 '17 at 11:55
  • really primitive version: IFS=$'\n' tinted=( $(tr -d '\r' < TintedRawRubberyChafer.txt | awk -F'=| ' '/^last=\w+ curr=\w+$/ {print $2, $4}' OFS=$'\n') ); last="$tinted[0]"; curr="$tinted[1]". Also, always quote your variables whenever you use them. – cas Jul 29 '17 at 12:07
  • sorry, the last part of that should be last="${tinted[0]}"; curr="${tinted[1]}". with the current input, that will set last=zcash and curr=btc. – cas Jul 29 '17 at 12:14

1 Answers1

1

Your '\r' comes from https://configmaker.com/my/TintedRawRubberyChafer.txt which has two defects:

  • its lines are CR-LF terminated (change this with tr -d '\r' or with dos2unix, sed, vim, etc)
  • its last line is not LF-terminated

So bash presumes you mean last=$'zcash\r'.

Morevover:

  • unless really necessary, you should quote your variables ("$last" not $last)
  • [-e $curr] should be written [ -e $curr ], or best [ -e "$curr" ] (spaces are important)
  • your | echo does not need a pipe. Just put echo on a separate line.
  • since you do not check for errors, your wget+source+rm could simply be written:

    source <(wget -O- https://configmaker.com/my/TintedRawRubberyChafer.txt)

xhienne
  • 17,793
  • 2
  • 53
  • 69
  • I am completely noob in bash programing, so can you explain me how to change it, or where do i need to use tr -d '\r'. Thanks. – Zhyhalo Oleksandr Jul 28 '17 at 15:11
  • Use your favorite editor and ask it to not terminate lines with CR-LF but just LF. Any serious editor should be able to offer this – xhienne Jul 28 '17 at 15:14