Using CmsShell on Ubuntu systems

CmsShell is a neat tool to access the OpenCms VFS from the command line. This can be extremely useful when your system can’t be accessed anymore using the web interface or when performing batch updates. The script can be found in the OpenCms webapp at WEB-INF/
Unfortunately the script that ships with the OpenCms webapp doesn’t work on Ubuntu systems as it is. These are the steps to make it run.
First be sure that it’s executable: chmod +x
When trying to run it using ./ you will very likely see an error:

bash: ./ /bin/sh^M: bad interpreter: No such file or directory

This is caused by dos line breaks that are included in the file. A tool to remove those can be found in the package tofrodos (used to be in sysutils):
sudo apt-get install tofrodos
Run it on the file by issuing
Try to run the file again: ./, which will result in another error:

/ 8: pushd: not found
./ 9: dirs: not found
./ 10: popd: not found
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencms/main/CmsShell
Caused by: java.lang.ClassNotFoundException: org.opencms.main.CmsShell
        at Method)
        at java.lang.ClassLoader.loadClass(
        at sun.misc.Launcher$AppClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(
        at java.lang.ClassLoader.loadClassInternal(
Could not find the main class: org.opencms.main.CmsShell.  Program will exit.

To make it work you need to open the script and change the line
OPENCMS_BASE=`dirs +0`
When saving the change and executing the script you should see OpenCms start and end at the prompt where you can login and execute any useful action you can think of.