1

I have very annoying problem here that I am completely lost on.

Am just trying to run a bash script from a php page.

The bash script is a long one.... so I created a caller.sh which calls the ./mainScript.sh to run in the background in the following:

nohup /bin/bash /home/test/customcoincode/CoinCreationBashFile.sh $coinName $coinNameAbreviation $blockReward $blockSpacing $targetTimespan $totalCoins $seedNode $nameSeedNode $headline >> /tmp/BASH2log.txt 2>&1 &

in reading my log file it seems some variables are not being passed in...

and at the following lines of code:

echo "Creating New Coin - Downloading code base repo"
echo "$localFolder/$coinName"
mkdir -p "$localFolder/$coinName";
cd "$localFolder/$coinName"
git clone "$baseRepository" "$localFolder/$coinName"
echo "Made it here 1"

i get outputs of:

Creating New Coin - Downloading code base repo
/home/test/Foocoin
cloning into '/home/test/Foocoin'
could not create directory '/var/www/.ssh'
host key verification failed
blah blah ....

Why is it looking in the /var/www/ directory?? works fine if I run the script from terminal?

many thanks

Fuzzybear
  • 1,388
  • 2
  • 25
  • 42
  • Not entirely, the `.ssh` directory is created there as 'personal config files' for apache. His paths are fine. This might help you: [Run a shell command as another user or change Apache's user?](http://stackoverflow.com/questions/5797816/run-a-shell-command-as-another-user-or-change-apaches-user) – AmazingDreams Aug 03 '13 at 17:38
  • thanks for your reply and I am starting to see what is possibly happening here then, but no that question really did not help or I am failing to see how I can use it :( – Fuzzybear Aug 03 '13 at 17:54
  • 1
    It might help if you create the `.ssh` yourself and give `www-data` or whatever user apache runs under on your system write acces to that folder. – AmazingDreams Aug 03 '13 at 17:59
  • 1
    As someone seems to have removed his/her comment that provided 3/4th of the explanation: The shell script is executed as the user apache runs onder. `/var/www` is his/her/its home directory. – AmazingDreams Aug 03 '13 at 18:03
  • thank you for your help and inclusion of the removed comments!! ok I created a .ssh directory in /var/www/ and that suppressed the can not create directory... now just the host key verification failed... take it i need to copy the keys i setup for github ssh push pull in that directory? – Fuzzybear Aug 03 '13 at 18:11
  • 1
    I'd create new ones for apache ;) saver that way. – AmazingDreams Aug 03 '13 at 18:12
  • 1
    You sir are a GOD!! thank you have solved all my problems and now everything works :) thank you so much – Fuzzybear Aug 03 '13 at 18:54
  • No problem, I have packed my comments in an answer :) – AmazingDreams Aug 03 '13 at 19:30

1 Answers1

2

So to pack up my comments in an answer:

The shell script is now run as apache, as git uses ssh, corresponding config files are needed. Which were created in /var/www; apaches home directory. Apache did not have write permissions in /var/www thus could not create these files.

To resolve, create the /var/www/.ssh directory yourself and give www-data (or whatever user apache runs under in your system) write access to that folder.

Next, github requires you to authorize ssh keys. It is safer to create a new one for apache in the newly created /var/www/.ssh directory and add this key to your github keychain.

AmazingDreams
  • 3,136
  • 2
  • 22
  • 32