COMPLETED
Technical summary
This project is a Bash rewrite of the original cwd utility (HostGator) to speed up operational navigation on cPanel servers. It resolves document roots by username or domain, supports optional subpaths (/blog, /wp-admin), and returns a valid cd command that can be evaluated in the current shell.
Executed scope
- Full rewrite of the original logic (Perl + XML API) into pure Bash.
- Removed dependency on cPanel XML API and WHM hash authentication.
- Implemented multi-source lookup over cPanel local files (
/var/cpanel/userdata,/etc/userdatadomains,/var/cpanel/users). - Added support for username, domain, and subdomain-based navigation.
- Implemented progressive fallback for non-existing subdirectories (closest valid parent).
- Added automatic shell wrapper installation into
.bashrc. - Added
-q(quiet) and-v(verbose) modes for automation and troubleshooting.
Docroot resolution architecture
Lookup order implemented for deterministic behavior:
- Treat input as cPanel account
usernamein/var/cpanel/userdata/<user>/. - Search exact domain file in account userdata.
- Validate
servername/serveraliaswhen exact filename does not match. - Query global index in
/etc/userdatadomains. - Fallback to DNS fields under
/var/cpanel/users/<user>. - Final fallback to
/home/<user>/public_html.
Practical execution
# basic usage
cwd [OPTIONS] username|domain[/subdir]
# by username
cwd linux
# by domain
cwd linux.com
# domain + subdirectory
cwd linux.com/blog
# quiet mode (scripts)
cwd -q nonexistentuser
# verbose mode (debug)
cwd -v wrongdomain.com
Wrapper and current-shell behavior
The wrapper solves the classic subshell limitation. Instead of executing cd in an isolated script process, it emits output to be evaluated in the caller shell:
# script output
cd /home/user/public_html
# apply in current shell
output="$(/path/to/cwd.sh domain.com 2>&1)"
eval "$output"
Operational troubleshooting
# validate account presence
ls /var/cpanel/userdata/username
# validate domain file
ls /var/cpanel/userdata/username/domain.com
# validate documentroot in userdata
grep documentroot /var/cpanel/userdata/username/domain.com
# check duplicate wrapper install in bashrc
grep -n "CWD AUTO-WRAPPER" ~/.bashrc
Stack and tooling
- Shell Script / Bash
- cPanel/WHM
- Linux
- grep
- sed
- cut
Operational tags
- cPanel
- Bash
- CLI
- SysAdmin
Operational outcome
- Account/domain navigation in seconds without remote API calls.
- Better reliability in incident scenarios where cPanel services may be degraded.
- Reduced triage time for web roots, logs and site files.
- Standardized command workflow for N1/N2/N3 support teams.
GitHub progress (issues)
Real-time panel with latest repository issues.
live feed
open issues on GitHubcarregando andamento...
não foi possivel carregar as issues agora. abra no github pelo link acima.
Real results
Bash rewrite of the classic cPanel cwd utility with docroot resolution by username or domain, smart fallback and automatic shell-wrapper installation.
Architecture and organization
- Shell Script / Bash
- cPanel/WHM
- Linux
- grep
- sed
- cut
Execution and operations
The project follows reproducible execution flow with technical validation in production-like environments.
Screenshots
Talk about this project
Apply this implementation pattern in your environment and accelerate delivery with technical consistency.