Can we create files in Linux server from front end html page? - java

I would like to know if we can create files from a html page in browser to the linux server folder? I have a shell script which creates txt files.. But when i trigger this script from browser using ajax it doesn't create any files.. I gave all permissions to the parent directory but still i dont see file creations nor any error.
test.sh
echo "first sh"
java HelloWorld
echo "t1 test" > t1s
if [ ! -f t1s ]
then
echo "Shell File is not created .."
else
echo "Shell file is created.. "
fi
------
first.php
<?php
$output=shell_exec('sh test.sh');
echo "Hello Php \r\n";
echo $output;
echo "done \r\n";
?>
-----------
This is the output from command line:
Hello Php
hello first sh Shell file is created..
done
----------------
This is the output from broswer:
Hello Php hello first sh Shell File is not created .. done

When executing scripts via your web server, it helps to note that the environment used by your webserver is rarely identical to the environment that you see as a CLI user. For example, the command
sh test.sh
makes two assumptions: sh is in your $PATH, and test.sh is in the current working directory. It is very likely that neither of these are true when your webserver tries to run the command.
For better results, try including full paths to both the command and the file. For example:
shell_exec('/bin/sh /var/www/html/scripts/test.sh');
Finally, check the executable permissions on test.sh to be sure that the web user (httpd, or apache, or whatever) has permission to execute that script.

Related

Not able to convert the csv to HTML in Jmeter

I am running load test on one of my sftp server application using jmeter. I run my jmx script as below
nohup sh jmeter.sh -n -t <jmx_file> -l <jtl_file> &
Script does have Simple Data Writer which creates csv file with result, which i convert into html using below command running on cmd from bin folder of jmeter.
jmeter -g <csv_path> -o <html_folder>
It was working couple of days back and now if i run the above command it gives error as below
The system cannot find the path specified.
errorlevel=3
Press any key to continue . . .
There was an update in my jdk from 1.8_241 to 1.8_251 and i have updated my java_home as well.
Do i need to do anything else in jmeter to make this work?
Double check that you can launch JMeter normally without nohup like:
./jmeter.sh --version
Ensure that the test is producing the .jtl results file and the file is up to date and not from the previous executions
Check the contents of nohup.out file
In general you should not be using any listeners, it is sufficient to have the .jtl results file in order to generate the dashboard and the dashboard can be generated during the test run like:
jmeter -n -t <jmx_file> -l <jtl_file> -e -o <html_folder>
if you don't have any background logic to remove "stale" jtl_file and html_folder you will need to add -f command-line argument to force JMeter to overwrite the old result file and dashboard folder like:
jmeter -n -f -t <jmx_file> -l <jtl_file> -e -o <html_folder>

Running selenium webdriver through jar file with upstart

i created a .jar executable file that when executed opens up two firefox selenium webdriver instances (two automated firefox instances) now when i execute the jar file through terminal likes this java -jar /opt/program.jar it works fine. but when i execute it through an upstart service:
program.conf
description "Desc"
author "Author"
start on filesystem
stop on shutdown
script
export HOME="/opt"
echo $$ > /var/run/program.pid
exec sudo /usr/bin/java -jar /opt/program.jar
end script
pre-start script
echo "[`date`] Starting" >> /var/log/program.log
end script
pre-stop script
rm /var/run/program.pid
echo "[`date`] Stopping" >> /var/log/program.log
end script
it doesn't launch any browser instances. just says
program start/running, process 14546
i would appreciate any help with how to go about doing what i am trying to do the correct way. thanks

PHP shell_exec() won't execute screen command to run .jar file

I am working on a minecraft control panel in Ubuntu and thus I need to start/stop a .jar filewith shell_exec();
When I try commands like "whoami", the output is normal. But when I try this:
shell_exec("screen -dmS mcsrv java -Xmx512M -jar /var/www/srv/craftbukkit.jar -o true nogui");
It does not do anything, I have checked the permissions too and www-data is the owner of the files
Try to redirect the standard error stream to stdout (by appending 2>&1 to the command), fetch that output and print it to check whether there was a meaningful error message
$cmd = "screen -dmS mcsrv java -Xmx512M -jar /var/www/srv/craftbukkit.jar -o true nogui";
$redirect = '2>&1';
// using variable substitution only for readability here
shell_exec("$cmd $redirect", $output);
var_dump($output);

Check if remote file exists Linux

I have following script that is used to check if file exists in remote Linux machine. Although it works when directly invoked on console, it does gets me prompt asking password when this script is invoked in Java via Runtime->exec()
`ssh $HOSTNAME test -f $FILENAME`
result=$?
result=0;
if [ $result != "0" ]; then
echo "$FILENAME is not found"
exit 31;
fi
I have also used the script adding user name as
`ssh root#HOSTNAME test -f $FILENAME
You need to recheck your ssh keys and which user you're running as for Java. If the keys don't match then you'll be prompted for a user/password.

I am trying this script which converts excel to sql have added necessary jars but something is missing Syntax or Java setting IN LINUX

Please give me a simple example with shell script explanation.
#!/bin/bash
#echo off
echo -n Enter acl File Location
read acl
echo -n Enter sql File Location
read sql
cd bin
java -classpath .;../lib/dom4j-1.6.1.jar;../lib/poi-3.8-20120326.jar;../lib/poi-ooxml-3.8-20120326.jar;../lib/poi-ooxml-schemas-3.8-20120326.jar;../lib/stax-api-1.0.1.jar;
../lib/xmlbeans-2.3.0.jar com/paywithisis/gateway/utility/XLSXToSQLConverter $acl $sql
cd ..
echo $acl
echo $sql
Linux uses : to sepearate the parts of the classpath windows uses ;

Categories

Resources