Closing the Environment Gap
Goal
When you hear "it works on our server," you will be able to suspect the environment rather than the code and pin down the difference within 30 minutes.
Why it matters
Environment problems are harder to find than code defects. You can see code by reading it, but there is nothing to read in an environment. That is why you need an order, and if you harden that order into a script, the round trips with the customer drop from three to one.
The three things covered in this lab are in order of frequency in the field. For environment variables, most of the time the place where it was set and the place where it is read differ. Encoding blows up overwhelmingly often with Korean customer data; CSVs made on Windows are often EUC-KR (CP949) rather than UTF-8, and a string read wrongly is stored quietly without any error and comes back weeks later as a report that search does not work. Permissions weigh especially heavily for credential files — if a token is left at 644, every other user on the same server can read it, and in a security review this one thing erodes trust in the whole project.
/opt/app/envcheck.sh is not something to fix. The assignment is to bring the environment into line with it.
Steps
- Create the
/root/envdirectory. - Run
bash /opt/app/envcheck.shas it is and save the failure output to/root/env/fail.txt. - Write the name of the environment variable that the failure message points to in
/root/env/missing_var.txt. - Convert
/opt/data/customers_kr.csvto UTF-8 and save it as/root/env/customers_utf8.csv. The Korean text must be readable. - Write the number of customer rows, excluding the header, in the converted file to
/root/env/kr_rows.txt. - Create
/root/env/token.txtand set its permissions to600. - Run
envcheck.shagain with the required environment variable supplied, and save the success output to/root/env/result.txt. - Write what was different in
/root/env/report.md. It must include the environment variable name, the encoding name of the original file, and the permission number you applied.
Notes
iconv -f EUC-KR -t UTF-8 입력 > 출력(replace the two placeholders with the input file and the output file)- Putting it before the command, as in
API_TOKEN=xxx bash /opt/app/envcheck.sh, applies it only to that run. chmod 600 파일(replace the placeholder with the file), and to check,stat -c %a 파일(again with the file)- Common mistake 1: doing
exportin another shell in step 7 and running it here. Environment variables are inherited along the process. - Common mistake 2: only copying without converting in step 4. Check that the Korean text is actually readable.
Create the working directory
Create the /root/env directory.
You collect the outputs under /root/env.
Reproduce the failure and save it
Run bash /opt/app/envcheck.sh as it is and save the failure output to /root/env/fail.txt.
If you just run bash /opt/app/envcheck.sh, it fails. Leave the output in a file as it is.
Write the missing environment variable name
Write the name of the environment variable that the failure message points to in /root/env/missing_var.txt.
The failure message tells you the variable name directly. Write only the name.
Revive the Korean CSV
Convert /opt/data/customers_kr.csv to UTF-8 and save it as /root/env/customers_utf8.csv. The Korean text must be readable.
/opt/data/customers_kr.csv cannot be read as UTF-8. Think of the typical encoding of files made on Korean Windows and convert with iconv.
Count the customer rows
Write the number of customer rows, excluding the header, in the converted file to /root/env/kr_rows.txt.
It is the number of data rows in the converted file, excluding the header.
Give the token file least privilege
Create /root/env/token.txt and set its permissions to 600.
Create /root/env/token.txt and make it readable and writable only by the owner. Use chmod's numeric notation.
Get the check to pass
Run envcheck.sh again with the required environment variable supplied, and save the success output to /root/env/result.txt.
Putting the environment variable before the command applies it only to that run. Leave the output of the passing run in a file.
Write the environment difference report
Write what was different in /root/env/report.md. It must include the environment variable name, the encoding name of the original file, and the permission number you applied.
Write three things that were different: the variable name, the encoding name of the original file, and the permission number you applied.