Skip to content

Instantly share code, notes, and snippets.

@rupertqin
Created February 27, 2023 03:23
Show Gist options
  • Save rupertqin/5ae89ef25cb2586f40060d17b7de7d4c to your computer and use it in GitHub Desktop.
Save rupertqin/5ae89ef25cb2586f40060d17b7de7d4c to your computer and use it in GitHub Desktop.
#!/bin/bash
user=root
file=environment.js
if [[ $server == develop ]]; then
host=150.158.6.63
path=/data/ncbd/env
port=22
elif [[ $server == develop-test ]]; then
host=150.158.153.13
path=/data/env
port=3600
elif [[ $server == develop-pc ]]; then
host=81.68.82.141
path=/home/qflowfe/dockerbuilder/env
port=22
elif [[ $server == qbi ]]; then
host=81.68.82.141
path=/home/qflowfe/dockerbuilder/env
file=environment_qbi.js
port=22
else
host=49.235.87.142
path=/data/env
port=22
fi
if [[ $key == "" ]]; then exit 0; fi
firstCharacter=${value:0:1}
if [[ $value == true || $value == false || $firstCharacter == [ ]]; then
quote=
else
quote=\'
fi
echo $host
echo "value: " $value echo "server: " $server
ssh -o "StrictHostKeyChecking no" $user@$host -p $port /bin/bash <<- EOF
cd $path
if grep -q $key: $file; then
sed -i "s@.*$key:.*@\ $key: $quote$value$quote,@g" $file
else
sed -i "3 i \ $key: $quote$value$quote," $file
fi
grep $key: $file
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment