arangosh
seems not to like having shebangs in javascript files loaded with --javascript.execute
I'm making sysadmin tools for our arangodb - tools that the guy with the root password will use when stuff breaks! Tools that wont ask for permission, that will bypass arangodb's permission restrictions. I use a unix socket for that.
So far I have made /opt/arango-tools/bin/arangojs
with:
#!/bin/bash
SOC=/var/lib/arangodb/unrestricted-endpoint
if [ -r $SOC ] && [ -w $SOC ]
then
/usr/bin/arangosh --server.endpoint unix://$SOC --javascript.execute "$@"
else
echo Needs R/W to $SOC, consider running with sudo
exit 1
fi
and then a simple helper tool /opt/arango-tools/bin/list-users.js
with:
#!/opt/arango-tools/bin/arangojs
var users = require("org/arangodb/users");
db._listDatabases().forEach(function(db_name) {
console.log(db_name);
db._useDatabase(db_name);
users.all().forEach(function(row) {
console.log(" " + row.user +
(row.active ? ' (active)':' (disabled)'));
});
});
but then when running it goes like:
mogul@guldager:~$ sudo /opt/arango-tools/bin/list-arangodb.js
2016-03-17T08:46:46Z [11876] ERROR JavaScript exception in file '/opt/arango-tools/bin/list-arangodb.js' at 1,1: SyntaxError: Unexpected token ILLEGAL
2016-03-17T08:46:46Z [11876] ERROR !#!/opt/arango-tools/bin/arangojs
2016-03-17T08:46:46Z [11876] ERROR !^
mogul@guldager:~$
Obviously a line starting with #!
is not valid javascript.
Suggestions / workarounds / ideas - anyone?
Its currently not possible.
However, we liked the idea, and ArangoDB 2.8.6 onwarnds will be able to do something like this:
#!/usr/bin/arangosh --javascript.execute
print('hello world')
It will for shure source the regular environment so you can do anything with this that
/usr/bin/arangosh --javascript.execute /tmp/test.js
could do before.