Run Remote Bash Scripts: Fix TERM
& Config File Errors
Running Bash scripts on a remote server via SSH sounds simple. But then, errors. TERM
variable issues. Missing config files. Frustrating? Absolutely. Here’s the direct fix.
Problem 1: Terminal Context Errors
You’re seeing TERM environment variable not set
or reset: terminal attributes
.
This means SSH didn’t give your remote command a full terminal context. Commands that expect one, like many interactive tools or even basic reset
, fail.
Solution 1: Force a pseudo-terminal. Add -t
to your SSH command.
Problem 2: The Missing Config File
Then there’s no configuration file provided: not found
from docker compose
.
Your script calls docker compose pull
. But when you run a script with its full path via SSH, its working directory isn’t necessarily the script’s directory. docker compose
can’t find compose.yaml
.
Solution 2: Change directory first. Execute your script from its own folder.
The Combined Fix
You’re running compose.bash
from /home/softwareshinobi/softwareshinobi.com/
on miura
.
Here’s the command that gets it done:
miura -t 'cd /home/softwareshinobi/softwareshinobi.com/ && bash compose.bash'
Why It Works
miura
: Your quick access alias to the server.-t
: Forces SSH to provide a terminal environment. No moreTERM
errors.'cd ... && bash ...'
: This executes two commands on the remote:cd /home/softwareshinobi/softwareshinobi.com/
: Moves into the script’s directory. Nowdocker compose
findscompose.yaml
.&&
: Ensures the script only runs if thecd
was successful.bash compose.bash
: Executes your script from its correct context.
Make It Even Easier: Your .bashrc
Shortcut
Typing that full command every time? Not efficient. Create a Bash alias in your local ~/.bashrc
.
Add this line to your ~/.bashrc
file on your local machine:
alias run_compose_miura="miura -t 'cd /home/softwareshinobi/softwareshinobi.com/ && bash compose.bash'"
Save and then reload your bashrc
:
source ~/.bashrc
Now, simply run:
run_compose_miura
One short command. Done.
Conclusion
Remote script execution doesn’t have to be a headache. Understand these two common SSH nuances, apply the -t
flag and a cd
command, and your scripts run clean. Streamline it further with a simple bashrc
alias. Simple, direct, effective.