running blender script via PHP shell_exec - ssh

Im trying to run the following command via my PHP script
$exe = "blender -b /var/www/renderer/tmp/abcd/abcd.blend -P /var/www/renderer/addon_execute.py -- -sx 300 -sy 600 -s 0.5 -sa 10";
$res = shell_exec( $exe );
The result im getting is
Read blend: /var/www/renderer/tmp/abcd/abcd.blend
Blender quit
Running the same script via SSH runs perfectly
What is wrong here ?

Related

pass commands server using perl openssh

there are 2 systems,
client system,
in which i am passing commands to the server by doing openssh to the server and my script goes like this
#!/usr/bin/perl
use lib "/home/geek/app/usr/lib/perl5/site_perl/5.8.8";
use lib "/home/geek/app/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi";
use lib "/usr/lib/perl5/5.8.8";
use Net::OpenSSH;
my $host = '******010';
my $user = '*****';
my $pass = '*****';
my $ssh = Net::OpenSSH->new("$user:$pass\#$host");
$ssh->error and
die "Couldn't establish SSH connection: ". $ssh->error;
my $out = $ssh->capture("/p/inway/bin/inway71 lib123 p123.0_CC default ");
#my $out = $ssh->capture("cd units; ls");
#$out = $ssh->capture("ls units/");
print "output is $out";
and in server /p/inway/bin/inway71 is a scripts:
#!/bin/sh
. $MODULESHOME/init/sh
module load lsf
exec bsub -Is -q interactive -J INWAY71_LSF -R 'type==X64LIN && osrel==50 && clearcase' /nfs/site/proj/inway/bin/inway71 ${1+"$#"}
so when i login to my server and run this script in my terminal, i will be directed to some path (i have no clue what it is, but i guess its one more server which i can login using this bash script) and i can do the rest of the activity like cd,ls,cat, etc etc)
but when i run this from my client system it passes the control to the terminal and waits for my input, and in my terminal i get an error saying,
stty:standard input:Invalid argument
In my terminal i can do ls or anything, but not able to do it from the perl script and capture the result.
How can i resolve this and get what i want?
That remote command expects to be run in interactive mode. This doesn't work with the SSH command mode. See this Net::OpenSSH FAQ!
You can:
find a way to pass commands as arguments to that script.
rewrite it to accept commands as arguments.
talk to it using Expect.

executing parameter file in a unix remote server

I am trying to run a script remotely using ssh and the need use some parameters from remote server. Kept all parameters in remote server location temp/test/test.prm file. Getting an error saying " invoke.sh: line 20: . /temp/test/test.prm: No such file or directory "
See below for sample script. Have very basic knowledge in scripting so plz direct me
#!/bin/sh
Param1=$1
Param2=$2
ssh usr#Server1
. ${Param1}/Client/scripts/Sample1.prm
cd $prmHome/$prmSetPath
ls | sed '/\.log$/d' > $prmHome/$prmScript/Filelist.txt
cd $prmHome/$prmScript
while read LINE
do
ExportFilName=$LINE
./conversion.sh $prmHome/tmp_export/convert_$Param2.csv $prmHome/$prmSetPath/'$ExportFilName'
done < Filelist.txt
rm -rf $prmHome/$prmScript/Filelist.txt
exit 0
Content of Sample1.prm
prmHome=/iis/home
prmSetPath=/export/set
PrmScript=/Client/scripts
I have tried the same trough command line after connecting to remote server using ssh and it is working, but when I am trying to do the same through a script (invoke.sh) its throwing no such file or directory error
UPDATE
This is unclear and will not work !
ssh usr#Server1
. ${Param1}/Client/scripts/Sample1.prm
As mentioned you should use
ssh usr#Server1 ". ${Param1}/Client/scripts/Sample1.prm"
format first.
And secondly what you expect following command to do ?
. ${Param1}/Client/scripts/Sample1.prm
Notice that there is a space in between . and the path, which is a synonym for source. So also check if the Sample1.prm have valid commands.
Looks like you are not running any ssh shell command on remote host but only on your local host.
How exactly you are running the ssh shell command ?
The code snippet in your example is poorly formatted.
The general structure should look like this e.g.
ssh user1#server1 date
or
ssh user1#server1 'df -H'
Please revise you invocation script, or make the formatting in the question appropriate.
Update:
If you want to execute your code on remote server via ssh, you can do following:
Create separate file my_script.sh for your code you want to run remotely, and paste following code:
#!/bin/bash
function my_function() {
prmHome=$1
prmSetPath=$2
PrmScript=$3
cd $prmHome/$prmSetPath
ls | sed '/\.log$/d' > $prmHome/$prmScript/Filelist.txt
cd $prmHome/$prmScript
while read LINE
do
ExportFilName=$LINE
./conversion.sh $prmHome/tmp_export/convert_$Param2.csv $prmHome/$prmSetPath/'$ExportFilName'
done < Filelist.txt
rm -rf $prmHome/$prmScript/Filelist.txt
exit 0
}
Then you can call you function remotely, by sourcing your file on remote server:
ssh usr#Server1 '. my_script.sh; my_function "/iis/home" "/export/set" "/Client/scripts"'
That's it :)
This code will not work:
ssh usr#Server1
. ${Param1}/Client/scripts/Sample1.prm
Change it like that:
ssh usr#Server1 ". ${Param1}/Client/scripts/Sample1.prm"

Calling a script from Java

I have a java program that uses the JSch libraries. I can successfully call scripts from it, but when calling one script I have that calls another script, it doesn't end up calling the other one. I have tested it in command line and it works just fine. I know I am calling the script correctly from Java because part of it executes. The script is below.
MOVIE_ROOT="/path/to/Movies"
IMDB_SCRIPT="/path/to/imdb-lookup/imdb-mf.sh"
MOVIE_FOLDER="$1"
MOVIE_FILE="$2"
MOVIE_NAME=${MOVIE_FILE%.*};
# If there isn't any info for the movie
if [ ! -f "$MOVIE_ROOT/$MOVIE_FOLDER/$MOVIE_NAME.jpginfo" ] ; then
cd "$MOVIE_ROOT/$MOVIE_FOLDER"; $IMDB_SCRIPT -p -t "\"$MOVIE_NAME\"" > "$MOVIE_ROOT/$MOVIE_FOLDER/$MOVIE_NAME.mvinfo";
exit 0;
fi
cat "$MOVIE_ROOT/$MOVIE_FOLDER/$MOVIE_NAME.mvinfo";
exit 0;
I also know that imdb-mf.sh works as well. I have echod out the line cd "$MOVIE_ROOT... and pasted that into command line and it works fine. The only time it doesn't work is when I run the script from Java. All the scripts have correct permissions set and are chmod +x. Any ideas on what's going wrong?

php issue when running on linux with dot slash filename format

I have a script (file1.php)in php in linux
#!/usr/bin/php -q
<?php
echo "hello world" ?>
when i run in linux (redhat # bash shell)
> php file1.php
it works. my php is in /usr/bin/php and its version is 5.3.3)
but when i run
./file1.php
it says
'./file1.php' not present.
my application requires this ('./file1.php') model to work
on my other machine this file works with ('./file1.php') model
why is it so , is there any way to fix this ..
**/usr/bin/php -v works well
file permission (file1.php): -rwxr-xr-x 1 root root**
You should indicate how your file should be executed. In bash, it's done using a shebang
Try adding this line add the very top of your php script:
#!/usr/bin/php
<?php echo 'Hello world!';
This would tell bash to run ./file.php as php /fullpath/file.php
More info http://en.wikipedia.org/wiki/Shebang_(Unix)

Automate scp website file transfer using a shell script

i have 3 digital ocean droplets, how to automate one droplet files to another 2 droplets, so i was write a scp shell script.
guys do you have any other suggestions or easily file transfer between two droplets?
#! /usr/bin/env bash
# Variables
SERVER1USER=root
SERVER1PSWD=killergirls
SERVER1IP=123.123.123.123
SERVER1PATH=/etc/var/html/www/
SERVER2USER=root
SERVER2PSWD=killerboys
SERVER2IP=121.121.121.121
SERVER2PATH=/etc/var/html/www/
echo -e "\n--- First Server files transferring now... ---\n"
sshpass -p "$SERVER1PSWD" scp -r /etc/var/html/www/ SERVER1USER#SERVER1IP:$SERVER1PATH
echo -e "\n--- Second Server files transferring now... ---\n"
sshpass -p "$SERVER2PSWD" scp -r /etc/var/html/www/ SERVER2USER#SERVER2IP:$SERVER2PATH
I prefer to program things like this in python. Below I have a sample of one script that I use to deploy hadoop to a cluster.
It can be expanded easily by adding more files, commands, or ips.
Note that I like being able to print everything that is going to be executed before I actually run it.
This is done with the DEBUG variable.
Also note, this can be accomplished in bash, but since I am not an accomplished Bash programmer, Python is much easier and less error prone for me.
DEBUG=1
import subprocess
call = subprocess.call
ips = []
for i in range(0,10):
ips.append("10.0.0.%d"%(i))
commands = 'ls; echo "Hello"'
def hadoop_setup(ip):
sshTemplate = "ssh hdfs#%s '%s;'"
for eachCommand in commands.split(";"):
sshCall = sshTemplate%(ip, eachCommand)
if DEBUG: print sshCall
else: call(sshCall, shell=True)
copyFileTemplate = 'scp %s hdfs#%s:/home/hdfs'
for file in ['.bashrc']:
for ip in ips:
copyFileCall = copyFileTemplate%(file,ip)
call(copyFileCall, shell=True)

Resources