1

I have created a shell script on a ubuntu server X with geth Node installed,to insert data in a smart contract in testnet blockchain. Further I am executing the shell script from a PHP file insertscript.php created on the same server X by using shell_exec command. When I call the PHP script from the command prompt , it gets successfully executed and data gets inserted in the blockchain . But when I call the php script from another server by using cURL or open it in the browser, I will see the error :

Fatal: Unable to attach to remote geth: dial unix ///home/ubuntu/.ethereum/testnet/geth.ipc: connect: permission denied

My shell script looks something like:-

#!/bin/sh
ATTACHPARAMETER="ipc:///home/ubuntu/.ethereum/testnet/geth.ipc"
INCIDENTUUID=${1:-"photo-55697b7f4a550511448499999999"}
USERUUID=${2:-"null"}
TIMESTAMP=$3
STATUS=$4

echo $INCIDENTUUID
echo $USERUUID
echo $TIMESTAMP
echo $STATUS

geth attach $ATTACHPARAMETER << EOF

var abi = [abi definition];
var address = "addressofContract";
var mycontract = web3.eth.contract(abi).at(address);
eth.defaultAddress = eth.accounts[0];
personal.unlockAccount(eth.accounts[0],'test');

mycontract.createIncident('$INCIDENTUUID','$USERUUID',$TIMESTAMP,$STATUS,{from:eth.accounts[0],gas:1400000});
console.log("Inserted");


EOF

Could you help in finding the cause of this error and also in finding a solution to the same?

3

This happens because your geth binary runs under one user_id, but the webserver runs under another user_id (probably nobody,www ,or etc)

You have to make the geth.ipc file readable and writable to your webserver, either by group access or by using the same user_id on both processes (the webserver and geth)

Also, note that you can not share geth access via IPC (Inter Process Communication) between 2 computers, the IPC works only inside a single computer because it is a kernel-level implementation of data sharing.

  • Hi Nulik...thanks for your response....In my code I changed geth attach $ATTACHPARAMETER << EOF to sudo geth attach $ATTACHPARAMETER << EOF and the Fatal error cannot be seen but the data is still not being inserted. Do you suggest to use rpc instead of ipc? – Webdev Dec 12 '17 at 7:11
  • I changed to rpc from ipc and the code worked...thanks – Webdev Dec 12 '17 at 13:10
  • I have the same error, but even when my .ipc file has 777 permissions I am seeing the "permission denied" issue – Barney Chambers Jan 17 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.