Sponsored Content
Top Forums Shell Programming and Scripting Smarter way to read $1 $2 in php Post 303033588 by baris35 on Monday 8th of April 2019 06:24:54 PM
Old 04-08-2019
Smarter way to read $1 $2 in php

Hello,
I am running under ubuntu14.04 with php5. When I run below php, it creates a token, then adds axaxax and bxbxbx into pc database, and at last, kills created token.
What I am trying to do is to add userid and password read from a file. I do not wish to enter username and password manually.
While surfing on google, I read that php does not read any variable from command line, according to being told though. So I gave up that method.
add_user.php
Code:
<?php
$szpc_ip="127.0.0.1";
$szAPIport="17000";
$szuserid="admin";
$szpassword="mypasswd";
// New User Profile
$szUsername="axaxax";
$szPassoword="bxbxbx";
$str=vsprintf("%s:%s",array($szuserid,$szpassword));
$strenc=base64_encode($str);
// Web API: createtokenbased64
$apiurl=vsprintf("http://%s:%s/token/createtokenbased64?encrpty=%s",array($szpc_ip,$szAPIport,$strenc));
$szreponse = file_get_contents($apiurl);
// Get token
$sztoken=substr($szreponse,6,strlen($szreponse)-8);
// Web API: add_user with token
$apiurl=vsprintf("http://%s:%s/server/add_user?token=%s&username=%s&password=%s",arr$
$szUsername,$szPassword));
$szuptime = file_get_contents($apiurl);
echo $szuptime;
// Web API: destroytoken with token
$apiurl=vsprintf("http://%s:%s/token/destroytoken?token=%s",array($szpc_ip,$szAPIport,$sztoken));
$szuptime = file_get_contents($apiurl);
?>

Instead above, I wrote a silly script creating text file, then I run it. Please do not laugh at me Smilie

Code:
while read COL1 COL2; do
sed -i "s|axaxax|$COL1|g" add_user.php
sed -i "s|bxbxbx|$COL2|g" add_user.php
echo "php add_user.php $COL1 $COL2" > output
sleep 2
chmod 755 output
./output
sleep 2
sed -i "s|$COL1|axaxax|g" add_user.php
sed -i "s|$COL2|bxbxbx|g" add_user.php
sleep 60 #added due to token creation frequency is limited by the software
done<user_pass.txt
exit 0

user_pass.txt (tab seperated file)
Code:
franco franchi
ciccio ingrassia

This way, it's okay but not smart method.
Could you please lead me how to do it in php?

Thank you very much
Boris
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read Embedded Newline characters with read (builtin) in KSH93

Hi Guys, Happy New Year to you all! I have a requirement to read an embedded new-line using KSH's read builtin. Here is what I am trying to do: run_sql "select guestid, address, email from guest" | while read id addr email do ## Biz logic goes here done I can take care of any... (6 Replies)
Discussion started by: a_programmer
6 Replies

2. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

3. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

4. Shell Programming and Scripting

Smarter conditional script with Table

Hi, currently I have a script with conditional checking. But it's not flexible to use, because i must create a more conditional script if there are more keyword (see table) required. Question is: Can I create a more smarter script that will be more flexible? I appreciate any help anyone can give... (8 Replies)
Discussion started by: jazzyzha
8 Replies

5. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

6. Shell Programming and Scripting

Php script read from $1

Hello, I am trying to inject data extracted via php-json to sql database but unable to run it in loop mode. It is working just for one data, then stops. If it's necessary, I can share the complete php file. test.php <?php include_once 'imdb.class.php'; //mysql config. $servername =... (4 Replies)
Discussion started by: baris35
4 Replies

7. Shell Programming and Scripting

How to tell php to read shell?

.... Solved.... .. .. Hello, I've read couples of similar threads to my question and I strongly believe that I am doing something wrong. What I'm trying to do is to process data with php. It reads data from shell script. Everything goes well but at the end it does not print what it reads... (0 Replies)
Discussion started by: baris35
0 Replies
IFX_PCONNECT(3) 							 1							   IFX_PCONNECT(3)

ifx_pconnect - Open persistent Informix connection

SYNOPSIS
resource ifx_pconnect ([string $database], [string $userid], [string $password]) DESCRIPTION
ifx_pconnect(3) acts very much like ifx_connect(3) with two major differences. First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection. Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (ifx_close(3) will not close links established by ifx_pconnect(3)). This type of links is therefore called 'persistent'. PARAMETERS
All of the arguments are optional, and if they're missing, defaults are taken from values supplied in php.ini (ifx.default_host for the host (Informix libraries will use INFORMIXSERVER environment value if not defined), ifx.default_user for user, ifx.default_password for the password (none if not defined). o $database - The database name, as a string. o $userid - The username, as a string. o $password - The password, as a string. RETURN VALUES
Returns: valid Informix persistent link identifier on success, or FALSE on errors. SEE ALSO
ifx_connect(3). PHP Documentation Group IFX_PCONNECT(3)
All times are GMT -4. The time now is 07:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy