LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 11-21-2005, 12:15 AM   #1
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Rep: Reputation: 30
perl's system() command


#!/usr/bin/perl

$LDAP_BASE_DN = "dc=fedora,dc=directory,dc=server";
$LDAP_USER_DN = "ou=People,$LDAP_BASE_DN";
$LDAP_GROUP_DN = "ou=Groups,$LDAP_BASE_DN";
$LDAP_HOST = "fedora.directory.server";
$LDAP_MIN_UID = "0";
$LDAP_HOME_DIR = "/home";
$LDAP_LOGIN_SHELL = "/bin/bash";
$LDAP_ADMIN_DN = "cn=Manager,$LDAP_BASE_DN";
$LDAP_ADMIN_PASS = "password";

$SID=system("ldapsearch -LLL -x -D $LDAP_ADMIN_DN -b $LDAP_BASE_DN -h $LDAP_HOST -w $LDAP_ADMIN_PASS sambaSID | grep -v \"dn:\" | awk -F: '{print \$2}' | sed '/^\$/d' | sed 's/.* //'");

$DOMAIN=system("ldapsearch -LLL -x -D $LDAP_ADMIN_DN -b $LDAP_BASE_DN -h $LDAP_HOST -w $LDAP_ADMIN_PASS sambaDomainName | grep -v \"dn:\" | awk -F: '{print \$2}' | sed '/^\$/d' | sed 's/.* //'");

that is my script, i'm trying to store the outputs of the two system() commands into a variable, but so far without success, it seams to print them into the screen when i run it, but when i try and add the following command

$tmp=system("echo \"$DOMAIN\"");

i get an output of

S-1-5-21-1518731841-841626861-2448829314
fedora
0

and witht his command

print "$DOMAIN";

i get an out put of

S-1-5-21-1518731841-841626861-2448829314
fedora

can someone tell me how to pipe the out of the system() command into a perl variable and not display it on screen.
 
Old 11-21-2005, 01:27 AM   #2
hypexr
Member
 
Registered: Oct 2003
Location: USA Fresno Callifornia
Distribution: Gentoo (workstation), ArchLinux (file/mail server), Freebsd (web server), Ubuntu (laptop)
Posts: 115

Rep: Reputation: 16
This probably isn't the best way but you can pipe the output to a file ">" and then read the contents fo the file into a variable.
 
Old 11-21-2005, 01:59 AM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Use backticks

example:
Code:
$tmp = `echo  \$DOMAIN`;
<edit> forgot to escape $</exit>

Last edited by xhi; 11-21-2005 at 02:10 AM.
 
Old 11-21-2005, 02:37 AM   #4
hypexr
Member
 
Registered: Oct 2003
Location: USA Fresno Callifornia
Distribution: Gentoo (workstation), ArchLinux (file/mail server), Freebsd (web server), Ubuntu (laptop)
Posts: 115

Rep: Reputation: 16
Thats cool... Just like bash
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find out if my system is i386, i486, or i586? Is there a system info command? mlsbraves Linux - General 6 02-17-2009 05:08 PM
execute system command in c alaios Programming 3 07-13-2005 06:26 AM
System info. command Risc91 AIX 8 03-16-2005 02:00 PM
where is command "cd" located? or is it a command/ system call? feetyouwell Linux - Software 5 10-01-2004 09:01 PM
system command hel[ warney_out Programming 4 09-04-2004 06:24 AM


All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration