Call xargv in php


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Call xargv in php
# 1  
Call xargv in php

Hello,
After I loose all my works/files couple days ago, I am trying to fix them with old backups.
Below I call a php file with shell script and it injects processed data into related database in mysql .

Current process gives below output:
http://127.0.0.1/vod-www/Top Gun 1986.mkv

But I wish to have get:
http://127.0.0.1/vod-www/TopGun.mkv

I am starting to explain... A bit big file, I am sorry...
I have run.sh, imdb.class.php, inject.php and list_of_movies.txt file

./run.sh

run.sh
Code:
while read -r line;do
php 44.php $line
sleep 2
done<list_of_movies.txt

list_of_movies.txt
Code:
TopGun.mkv

44.php
Code:
<?php
include_once 'imdb.class.php';
//mysql config.
$servername = "127.0.0.1";
$username   = "root";
$password   = "my_password";
$dbname     = "stalker_db";
$dbport     = "3306";

//open mysql connection.
$conn = new mysqli($servername, $username, $password, $dbname, $dbport);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//read video database to array.
$sql = mysqli_query($conn, "select * from video ORDER BY name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
    $video[] = $row;
}
#################################################################
#        $aTests = [
#                    '$argv',
#                ];
#################################################################
//grab info from imdb.
$i = 1 ;
#foreach ($aTests as $sMovie) { #--------!!!
foreach($argv as $sMovie) {
   $i++;
   $IMDB = new IMDB($sMovie);
if ($IMDB->isReady) {
$title = $IMDB->getTitle($bForceLocal = true);
$description = mysqli_real_escape_string($conn, $IMDB->getDescription());
$plot = mysqli_real_escape_string($conn, $IMDB->getPlot($iLimit = 0));
..
..
..#to make it shorter, had to delete other lines###
if (!isset($last_id)) {
$adddate = date('y-m-d H:i:s');
$sql = "INSERT INTO video (name, o_name, cost, time, protocol, category_id, cat_genre_id_1, accessed, status, description, director, country, year, actors, added, rating_kinopoisk, rating_mpaa)
VALUES ('$title $year', '$title $year', '0', '$runtime', '', '2030', '459', '1', '1', '$description',  '$director', '$country', '$year', '$cast', '$adddate', '$rating', '$mpaa')";
if ($conn->query($sql) !== TRUE) {
    echo '<p style="text-align: center;">Error: ' . $sql . '<br>' . $conn->error . '</p>';
} else {
$last_id = $conn->insert_id;
}

//get next id for screenshots table.
$sql = mysqli_query($conn, "SHOW TABLE STATUS LIKE 'screenshots'");
$next_screenshot =  mysqli_fetch_assoc($sql)['Auto_increment'];

//now we will add poster to movie.
$screenshot_file = $next_screenshot . '.jpeg';
if (!copy("/root/$poster", "/var/www/stalker_portal/screenshots/136/$screenshot_file")) {
    echo "failed to copy $screenshot_file...\n";
}
$sql = "INSERT INTO screenshots (name, type, media_id)
VALUES ('$screenshot_file', 'image/jpeg', '$last_id')";
if ($conn->query($sql) !== TRUE) {
    echo '<p style="text-align: center;">Error: ' . $sql . '<br>' . $conn->error . '</p>';
}

//add file under movie directory.
$url = 'http://127.0.0.1/vod-www/'.$title.'.'.$year.'.mkv';
..
..
#then insert into sql commands follow....
$result = mysqli_query($conn, "SELECT * FROM video_series_files WHERE url='$url'");


The problem is related to this field:
Code:
//add file under movie directory.
$url = 'http://127.0.0.1/vod-www/'.$title.'.'.$year.'.mkv';

The data injected into mysql table is:
http://127.0.0.1/vod-www/Top Gun 1986.mkv

But I wish to have get:
http://127.0.0.1/vod-www/TopGun.mkv

I replaced:
$url = 'http://127.0.0.1/vod-www/'.$title.'.'.$year.'.mkv';
by
$url = 'http://127.0.0.1/vod-www/'$xargv'.';
but did not work. Also tried different variations but no luck.
I have checked my previous posts and I do not remember how I solved it earlier.

Thank you
Boris


Solved now:
I assumed that I should create a variable for filename but have just seen that a variable for that purpose was already created earlier in code..
$url = 'http://127.0.0.1/vod-www/'.$sMovie.'.mkv';
Solved the problem Smilie


Kind regards
Boris

Last edited by baris35; 05-02-2019 at 08:31 AM..
This User Gave Thanks to baris35 For This Post:
# 2  
Seems a bit strange and "messy" to me to use a shell script to call a PHP file in a loop.

The first think I would do is to make it a 100% PHP script and move the loop into your PHP program and read the command line arguments using PHP.

That is a cleaner way to program.
This User Gave Thanks to Neo For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #600
Difficulty: Medium
Functions in C do not need be declared before they can be used.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. UNIX for Advanced & Expert Users

Using PHP , call a sql inside a unix script

I am running the xampp on WINDOWS, and my php script is connecting to a unix script on a different server (ssh2_connect("11.31.138.56", 22). I am running the unix script and inside this script I am calling the .sql file . The SQL is connecting to oracle db on the unix server. But the sqlplus... (2 Replies)
Discussion started by: madfox
2 Replies

3. Programming

need help with system call

hi everyone i wrote a system call and compiled the kernel succesfully... my system call is in a file in the kernel folder named my_syscall1.c (kernel/my_syscall1.c) the header file for this system call i added it in the folder include like this include/my_syscall1/my_syscall1.h my problem is... (2 Replies)
Discussion started by: demis87
2 Replies

4. UNIX for Dummies Questions & Answers

Why do I need to call make if I call gcc ?

Why do I need to call make if I call gcc ? I thought gcc already compiles the sources. thanks (1 Reply)
Discussion started by: aneuryzma
1 Replies

5. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

6. Programming

c system call

How the c compiler differentiates the system calls and function calls? (1 Reply)
Discussion started by: rangaswamy
1 Replies

7. Shell Programming and Scripting

Call shell script from php not run ?

Hi. I write a shell script for import data to oracle using sql loader. I set permission 755 or 777 for that script. I can run that script in the consol okay. When I call it from PHP using system command. I got return value 126 this value when don't have permission right ? I check step... (2 Replies)
Discussion started by: raccsdl
2 Replies

8. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

Featured Tech Videos