Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-07-2005, 09:26 AM
|
#1
|
Member
Registered: Jun 2004
Location: KY
Distribution: Debian, Mint, Puppy
Posts: 507
Rep:
|
scripting question...
All righty, I was just wondering something. Is it possible to make a script that will call another script...but that script is not within the same language? Say a PHP script calling a BASH script or something?
What I am hoping to accomplish is that a username variable will get added to a MySQL Database via PHP or something...then another script will extract that username and add them as a system user so they can have their own directory for FTP and what not.
Could something like this be done. I have done PHP scripting but nothing like this...haven't done BASH scripting yet but willing to learn, especially to do what I am talking about here.
|
|
|
11-07-2005, 09:38 AM
|
#2
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
Yes. You just have to know what each item uses for input/output mechanisms.
For example in bash it uses variables which can be defined by name or by number if positional. So on the command line you type something like:
export TEST=<testarg>
within your bash script you just call the variable by prefixing its name with a $ for example:
echo "Now using $TEST within my script."
The above command would replace $TEST with whatever you'd typed in as <testarg> during the export.
A more common way though would be to use positional parameters. Any argument on the command line to a script gets a numeric value starting with 1 so that the first argument is $1, the next is $2 and so on.
So say you have a script named talkback.sh that just contains:
#!/bin/bash
echo "You typed $1"
Typing "talkback supecalifragilisticexpiallodocious" would result in:
You typed supecalifragilisticexpiallodocious
In Perl it uses argv[] as the input argument designator so your first would be argv[1], your second argv[2] and so on.
So you just need to know what PHP uses for such positional arguments to be able to pass one into it. I don't use PHP but am quite sure it must have such a mechanism.
|
|
|
11-09-2005, 05:52 AM
|
#3
|
LQ Newbie
Registered: Jul 2004
Distribution: Debian 2.4.18
Posts: 19
Rep:
|
to run a program from a php script use the function:
exec("/usr/sbin/yourscript");
or system("/usr/sbin/yourscript"); if I'm not wrong
You can run any program like this. Of course the path could be different
But make sure that there are the right privileges, and that you won't compromise the system security by doing this.
|
|
|
All times are GMT -5. The time now is 06:56 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|