fopen doesnt work if script run by shell_exec - fopen

I have a strange issue on my LAMP installation. I have a php script with function that save a log to a file using fopen().
If I run the script by shell_exec($scriptfilewithpath) nothing happens (it may give some errors but I am not sure how to get it from shell_exec.
If I run the script from the ssh console (sudo php /opt/bitnami/apache2/htdocs/script.php ) I get " PHP Warning: fopen(/opt/bitnami/apache2/htdocs/log.log): failed to open stream: No such file or directory in /opt/bitnami/apache2/htdocs/script.php on line 18" .
root and bitnami(used to install and set up LAMP) users have full access to script folder.
Any ideas where I am going wrong?
Thanks

Related

Installing files via Composer via Command Line | "'$' is not recognized as an internal or external command, operable program or batch file."

So I am attempting to install some files from Send Grid via Composer usind the CommandLine.
I am following a tutorial with the link here https://www.youtube.com/watch?v=fEobqi3N7zw
The guy in the video has no problem using Composer via the Command Line in the Windows Command Prompt, but when I input the command $ go_www, my PC whines and stamps it's feet, giving me the following line:
'$' is not recognized as an internal or external command,
operable program or batch file.
In a nutshell, why?
System Information:
Windows 10 64x
I have looked at other posts on here, to no avail, I have tried opening the Command Line too as System Administrator, but to avail. I have tried restarting the system, to no avail, I can confirmed I have composer installed into the correct directory, to no avail .
$ in a shell indicates the shell is not owned by a superuser, it is not part of the command. Try running go_www. Also, the video you linked seems to be using a bash shell, whereas you appear to be running a Windows command prompt from the error message you included in your question, which might be a problem too.
In any case, go_www is an alias the video author uses to quickly navigate to the folder of interest. Try manually navigating there using cd.

Can't open perl script "./script.pl": Permission denied

I get the error when trying to run a script. The script previously worked, but I edited one part of the code in Notepad++ (I change a ">" to a "<" ).
Any help would be appreciated! I was wondering whether it was a formatting issue after editing and saving in Notepad++ or if somehow my edit breaks the script.
(I'm using Ubuntu for Windows)
I've tried using sudo & sudo chmod a+x before the script, but this doesn't seem to help.
The error message indicates that perl is unable to read the contents of the file script.pl.
Since it is not clear who the script's owner is, you may give read permission to everyone using the following, sudo chmod a=rx path/to/script.pl.

How to load scripts in MongoDB

I'm using MongoDB version 3.0 and I want to run script.js on database
Problem I have find is that mongo is not seeing my file script.js.
What I have done step by step:
I have installed MongoDB in directory MongoDB\Server\3.0\bin\
I have put script.js inside \bin directory
I want to do is run script.js using load() method
I have got an error
load("script.js")
2016-10-09T22:17:17.557+0200 E - file [script.js] doesn't exist
2016-10-09T22:17:17.558+0200 E QUERY Error: error loading js file: script.js
at (shell):1:1
Probably I have put script.js in wrong place but where I should put it?
Next step is I'm using mlab and I want to load my script to the online server, how to do this?
I don't know of any magic that would make a \bin directory relevant, but assuming that your script is located in /bin, you just need to call out the full path when you do the load from within the mongoshell
load('/bin/script.js');
If your script is located off your home directory it will be like
load('/Users/yourname/script.js');
See the docs for load: https://docs.mongodb.com/manual/reference/method/load/
Ditto for how you run it on "the server". Its not so much running on the server, but in the shell that you are running. If the shell is connected to a particular server, the effects of the script will be on the server but the script itself executes in your shell.
For windows try:
load('c:\MongoDB\Server\3.0\bin\prova.js')
load("C:\\Data\\Mongo\\M001\\loadMovieDetailsDataset\\loadMovieDetailsDataset.js")
Double \ does the trick. I was receiving similar error as my install path was not set and the file res
Try changing the name of the .js file. In my case, the error was coming because the folder name and the file name were the same.

Perl script failing to open file for writing on first run but succeeding on second run

This script fails on the first run but succeeds the second time it is run with the same output_dir argument.
$output_dir is an argument passed in by user such as "/home/user/mydir".
Failing line:
open(StepOne, ">$output_dir/Step_One_Create_Resources.sh");
OS is Ubuntu 12.04
This seems like a permissions issue but I'm running the script as root.
Yes, maybe it is true that the $output_dir didn't exist when you call open(StepOne, ">$output_dir/Step_One_Create_Resources.sh") for the first time.So ,I strongly advise you to wait until the directory is created.
do{
}while(!(-e $output_dir));
open(StepOne, ">$output_dir/Step_One_Create_Resources.sh") or die $!;
this will make sure you open the output_dir just after the output_dir is actually created!
I found out what was causing this issue. When a directory that doesn't exist was being passed in as the output directory, the script would create the dir but it was failing to open a file at that location. The script runs fine when the output dir already exists.

Unable to run PostgreSQL as Windows service

I had this in my Windows services:
C:/Program Files/PostgreSQL/8.4/bin/pg_ctl.exe runservice -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w
It never finishes executing. But if I did this on the dos shell:
C:/Program Files/PostgreSQL/8.4/bin/pg_ctl.exe start -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w
Notice that I only changed the "runservice" to "start" and it works just fine.
Any idea?
The command runservice can only be executed by the service manager
in order to fix my localhost windows 7 to start postgres as a service
i used the following command to start the data
pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" start
Then checked the status for errors
pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" status
if you get error 1063 , its more than likely permissions, i executed the following command
cacls "C:\Program Files\PostgreSQL\9.1\data" /E /T /C /G postgres:F
then reran the start/status, it showed everything fine, but still service manager would not start the service
So, in Services->postgresql->options->logon i set the log on as the Local system account instead of the postgres user, and voila it worked
this happened to me because i set my data directory to be somewhere the postgres windows user account didn't have access to.
I had this problem in Windows after a system crash. Running the first command showed invalid data in C:\Program Files\PostgreSQL\9.1\data\postmaster.pid. Deleting that file did the trick. Reference.
I faced the same issue after moving manually the database data files (PG_DATA directory) without recreating all the necessary permissions.
Here is how I solved my issue:
1. Check permissions on old PG_DATA directory:
cacls "c:\path\to\old\pgdata\dir"
2. Check permissions on new PG_DATA directory:
cacls "d:\path\to\NEW\pgdata\dir"
3. Compare outputs from 1. and 2.
Find the differences between users and/or permissions then synchronize them.
Nota: I found it easier to use explorer for the synchronization step rather than using cacls directly from the command line.
If you changed pg_hba.conf , maybe you missed somewhere in file. For example there must be CIDR after IP in that file. It must be like 192.168.1.100/32
If you forgot to put 32, then server doesnt restart.
Investigation of startup logs could be a clue. For the case problem is in the pg_hba.conf you could see something like this:
2018-11-13 00:39:34.841 PST [8284] FATAL: could not load pg_hba.conf
2018-11-13 00:39:34.842 PST [8284] LOG: database system is shut down
You need to check your logfiles and the windows eventlog for some hint of what the problem is. If there is nothing at all there, you need to break out something like Process Monitor and get a stacktrace of where it's hung.
I have had this issue in the past, and it was that the installer did not set up the permissions correctly for the user that the service was to run as.
I've also ran into this problem with postgresql throwing and error after trying to initialize the database cluster. After analyzing the log files and running command line scripts for 4 hours I've got the solution to anyone running into this problem for Windows Versions.
This is not a detailed description as to why its happening. I've installed odoo 10, 11, 12 and 13 numerous times on countless client servers and windows systems and this is the first time I've ever ran into this problem. I cant say if its because I have MS VS Enterprise installed and Android Studio on this machine or what. But Below is the easy answer on how to fix it and initialize the cluster and create the database files in the data folder.
Open the data folder for postgresql. - For Odoo installs it will normally be "C:\Program Files (x86)\Odoo 13.0\PostgreSQL" Unless you chose another location when installing.
Remove any or all files from this folder - If not you will get an error when running initdb.exe
Right click the data folder and open up the properties for it. Click on the Security tab and then click the advanced button on the bottom.
You need to change the owner of this folder to openpgsvc. Click Change and type in openpgsvc and click ok. Once done click the check box below saying that you want this change to affect containers with this container as well.
Then on the Permissions tab click the add button on the bottom. You need to add openpgsvc as a user and give this user full rights. Click apply and and ok to close out of all the folder properties.
Now you need to open cmd.exe - Once open we are going to call initdb.exe and pass some values to it as well.
First run chdir and change the working directory to the location of initdb.exe. For me, running odoo 13 on a windows 10 machine the location is this..
"C:\Program Files (x86)\Odoo 13.0\PostgreSQL\bin"
There is one variable that need to be passed as well to make this work here is the list. NEEDS TO BE INCLUDED IN THE CALL TO initdb.exe
Postgres Data Dir: "C:\Program Files (x86)\Odoo 13.0\PostgreSQL\data"
The End Result with the parameter would look like this for my installation:
"C:\Program Files (x86)\Odoo 13.0\PostgreSQL\bin\initdb.exe" -D "C:\Program Files (x86)\Odoo 13.0\PostgreSQL\data"
Hit Enter and let it rip. The output of this command should look like this below.
Cmd.exe running initdb.exe script
Make sure there is no buggy empty file Program at C:\ like C:\Program
In this case, explorer will warn whenever you log on into Windows.
File Name Warning
-----------------
There is a file or folder on your computer called "C:\Program" which
could cause certain applications to not function correctly. Renaming it
to "C:\Program1" would solve this problem. Would you like to rename
it now?
Installing PostgreSQL 10 On Windows 7 (yes the clock is ticking...). I first tried the latest version 11 which completely failed to install... not a good sign for Windows users. Anyway.
Quick answer: Change the account in the Windows Services panel from Network to Local.
Details of my case
During installation I created/selected a data folder in the user profile folder, because obviously the folder suggested by default, within the program folder, wouldn't work, and if it worked it would be a very idea to put data here (I don't know whether it's usual to do that on Unix/Linux, but for Windows it's it's not allowed for a long time).
At the end (when populating the data cluster) I received an error:
Failed to load SQL Modules into database Cluster
but the installation was able to complete. I found two pages about previous error, here and here, but they didn't seem relevant to my case, so I just started pgAdmin and, on the left "browser", saw the server wasn't active.
I tried to start it from here (had to type the main password), but it went inactive immediately again. So I tried to use the Windows services panel to start "postgresql-x64-10", no joy. I copied the command from this panel and pasted it into a Windows console (cmd.exe) where I finally received this
error 1063.
Searching I found this related question, and was convinced the problem was about permissions.
Solution working for my case
In the services panel I changed the account used to start the service from Network Service to Local System as suggested in a comment by #AlexanderRios.
sc create "postgresql-9.2" binPath= "\"C:/Program Files (x86)/PostgreSQL/9.2/bin/pg_ctl.exe\" runservice -N \"postgresql-9.2\" -D \"C:/Program Files (x86)/PostgreSQL/9.2/data\" -w" DisplayName= "postgresql-9.2" start= auto
Try this on CMD run as Administrator
(Add your parameters depend on your version)
Stop all postgres processes
Go to the postgres data folder (C:\Program Files\PostgreSQL\9.6\data)
Delete the postmaster.opts and postmaster.pid files
From the control panel, in administrative
tools and the services console start the postgres service
open pgAdmin III and then in right pane find server then just right click and connect, enter the password. after connected go to the browser and refresh ODOO. Problem solved.
See image to get better understanding