Use this script file to
su into the cpanel user defined by the path.
#!/bin/bash THISUSER=`pwd | cut -d'/' -f 3` echo echo now running as $THISUSER; echo su $THISUSER -s /bin/bash
This is a easy option if you need to work on files as the correct owner.
For example, if the path is
/home/username/this/file path, you will su as
cat > ~/suthis.sh <<- EOM #!/bin/bash THISUSER=\`pwd | cut -d'/' -f 3\` echo echo now running as \$THISUSER; echo su \$THISUSER -s /bin/bash EOM chmod +x ~/suthis.sh
Now you can run it by typing
This version takes several extra optional parameters and will run them against using user determined user. If no parameters, then open a shell with that user.
Download and install this script by running the following
cat > ~/suthis.sh <<- EOM #!/bin/bash THISUSER=\`pwd | cut -d'/' -f 3\` echo if [[ \$* ]]; then echo Running commands as \$THISUSER echo for i in \`seq 1 \$#\` do eval a=\\\$\$i echo "Run: '\$a'" echo su \$THISUSER -s /bin/bash -c "\$a" echo done else echo Now running as \$THISUSER echo su \$THISUSER -s /bin/bash fi EOM chmod +x ~/suthis.sh
You can open a shell as above. Or run a command by passing it as an optional parameter. Use double quotes for commands with spaces.
~/suthis.sh "ls -l"
You can have as many commands as you like.
~/suthis.sh "ls -l" ls "ls" "echo hello"