Sponsored Content
Top Forums Shell Programming and Scripting how to print out data from mysql table in perl script Post 302482466 by kpddong on Wednesday 22nd of December 2010 02:06:08 PM
Old 12-22-2010
how to print out data from mysql table in perl script

I'm having trouble with this code.

if i do

.\read.pl -u user

it prints out

2010-12-20 12:00:00 host1 <cmd>a
2010-12-20 12:00:01 host1 <cmd> <execute>
2010-12-20 12:00:02 host1 <cmd>b
2010-12-20 12:00:03 host1 <cmd>c

however, if i enter
.\read.pl -h host1

it should print out
2010-12-20 12:00:00 user <cmd>a
2010-12-20 12:00:01 user <cmd> <execute>
2010-12-20 12:00:02 user <cmd>b
2010-12-20 12:00:03 user <cmd>c

and when i use this option
.\read.pl -u user -h host1

it prints out
2010-12-20 12:00:00 host1 <cmd>a
2010-12-20 12:00:01 host1 <cmd> <execute>
2010-12-20 12:00:02 host1 <cmd>b
2010-12-20 12:00:03 host1 <cmd>c

when i want it to print out
2010-12-20 12:00:00 <cmd>a
2010-12-20 12:00:01 <cmd> <execute>
2010-12-20 12:00:02 <cmd>b
2010-12-20 12:00:03 <cmd>c

can someone help me? can i not use the !defined() method? Thanks.

Code:
 
# DBI connection statement
my $dbh = DBI->connect("DBI:mysql:$database:$host", $user, $pw, {RaiseError=>1}) or die $DBI::errstr;
# Command line options
our ($opt_u, $opt_h, $opt_s, $opt_e, $opt_c);
getopt('u:h:s:e:c');
# Different queries
my $query;
my $sth;
if (defined($opt_u) && !defined($opt_h && $opt_s)) {
$query = ('SELECT time, host, cmd FROM '.$table.' WHERE user = "'.$opt_u.'"');
$sth = $dbh->prepare($query);
$sth->execute();
while (@ary = $sth->fetchrow_array()) {
foreach(@ary) {
print "$_ ";
}
print "\n";
}
}
elsif (defined($opt_h) && !defined($opt_u && $opt_s)) {
$query = ('SELECT time, user, cmd FROM '.$table.' WHERE host = "'.$opt_h.'"');
$sth = $dbh->prepare($query);
$sth->execute();
while (@ary = $sth->fetchrow_array()) {
foreach(@ary) {
print "$_ ";
}
print "\n";
}
}
elsif (defined($opt_u && $opt_h) && !defined($opt_s)) {
$query = ('SELECT time, cmd FROM '.$table.' WHERE user = "'.$opt_u.'" AND host = "'.$opt_h.'"');
$sth = $dbh->prepare($query);
$sth->execute();
while (@ary = $sth->fetchrow_array()) {
foreach(@ary) {
print "$_ ";
}
print "\n";
}
}

---------- Post updated 12-22-10 at 02:06 PM ---------- Previous update was 12-21-10 at 02:44 PM ----------

can someone help please

Last edited by pludi; 12-23-2010 at 08:39 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Inserting data in mysql table

Cant understand the error #!/bin/bash temp="" A="" D=$(date +"%Y-%m-%d") H=$(date +"%R") temp=$(wget -q -O - website | grep -o "Temperature:]**" | grep \-E -o "+") mysql -D "weather_wise" -e "INSERT INTO weather (Date, Hour, Degrees) VALUES ($D,$H, $temp)"; my data types for... (11 Replies)
Discussion started by: vadharah
11 Replies

2. Shell Programming and Scripting

How to scan data directly from Table using a script

Hi, I have a new task where i have two tables Acct_ open and lookup table In the Acct_open table there is all the information about an account including account number and lookup table is having a country code and corresponding country name where that account has been opened. both... (2 Replies)
Discussion started by: manmeet
2 Replies

3. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

4. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

5. Shell Programming and Scripting

Shell script for adding a table in mysql with 10,000 lines ... pls help

Hi , I am new to shell scripting . I need to write a shell script in sql to add 10,000 lines of data in a table . Pls help guys :) ---------- Post updated at 07:08 PM ---------- Previous update was at 03:40 PM ---------- guys please help !!! (3 Replies)
Discussion started by: vinumahalingam
3 Replies

6. Shell Programming and Scripting

Input data of a file from perl into HTML table

Hi , I need an help in perl scripting. I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below. cat out.txt This is the first line this is the second line. .....Now, this file needs to be send in mail in HTML... (2 Replies)
Discussion started by: scott_cog
2 Replies

7. Shell Programming and Scripting

Need to Print output in table using shell script

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (4 Replies)
Discussion started by: ankit.mca.aaidu
4 Replies

8. Programming

MYSQL merge csv data with exisiting table

I have a MYSQL table with demographic data. The addresses contained in the table were entered manually before the advent of online postcode lookup software and, hence, there are a lot of errors when using automated online mailing checking software. I plan to export the data as csv file for a 3rd... (1 Reply)
Discussion started by: barrydocks
1 Replies

9. Shell Programming and Scripting

Send Data to MySQL Table Columns

I have two scripts, each script reads an individual data file and copies specific lines of data and sends to MySQL table. Only difference is, each script sends data to a separate column on the same DB. I want to use one script to populate DB table and have data look horizontal, with no overlapping.... (3 Replies)
Discussion started by: SysAdminRialto
3 Replies
gsscred(1M)						  System Administration Commands					       gsscred(1M)

NAME
gsscred - add, remove and list gsscred table entries SYNOPSIS
gsscred [ -n user [-o oid] [-u uid]] [-c comment] -m mech -a gsscred [ -n user [-o oid]] [-u uid] [-m mech] -r gsscred [ -n user [-o oid]] [-u uid] [-m mech] -l DESCRIPTION
The gsscred utility is used to create and maintain a mapping between a security principal name and a local UNIX uid. The format of the user name is assumed to be GSS_C_NT_USER_NAME. You can use the -o option to specify the object identifier of the name type. The OID must be specified in dot-separated notation, for example: 1.2.3.45464.3.1 The gsscred table is used on server machines to lookup the uid of incoming clients connected using RPCSEC_GSS. When adding users, if no user name is specified, an entry is created in the table for each user from the passwd table. If no comment is specified, the gsscred utility inserts a comment that specifies the user name as an ASCII string and the GSS-APIsecurity mechanism that applies to it. The security mechanism will be in string representation as defined in the /etc/gss/mech file. The parameters are interpreted the same way by the gsscred utility to delete users as they are to create users. At least one of the follow- ing options must be specified: -n, -u, or -m. If no security mechanism is specified, then all entries will be deleted for the user identi- fied by either the uid or user name. If only the security mechanism is specified, then all user entries for that security mechanism will be deleted. Again, the parameters are interpreted the same way by the gsscred utility to search for users as they are to create users. If no options are specified, then the entire table is returned. If the user name or uid is specified, then all entries for that user are returned. If a security mechanism is specified, then all user entries for that security mechanism are returned. OPTIONS
-a Add a table entry. -c comment Insert comment about this table entry. -l Search table for entry. -m mech Specify the mechanism for which this name is to be translated. -n user Specify the optional principal name. -o oid Specify the OID indicating the name type of the user. -r Remove the entry from the table. -u uid Specify the uid for the user if the user is not local. EXAMPLES
Example 1: Creating a gsscred Table for the Kerberos v5 Security Mechanism The following shows how to create a gsscred table for the kerberos v5 security mechanism. gsscred obtains user names and uid's from the passwd table to populate the table. example% gsscred -m kerberos_v5 -a Example 2: Adding an Entry for root/host1 for the Kerberos v5 Security Mechanism The following shows how to add an entry for root/host1 with a specified uid of 0 for the kerberos v5 security mechanism. example% gsscred -m kerberos_v5 -n root/host1 -u 0 -a Example 3: Listing All User Mappings for the Kerberos v5 Security Mechanism The following lists all user mappings for the kerberos v5 security mechanism. example% gsscred -m kerberos_v5 -l Example 4: Listing All Mappings for All Security Mechanism for a Specified User The following lists all mappings for all security mechanisms for the user bsimpson. example% gsscred -n bsimpson -l EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWgss | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
gssd(1m), See gsscred.conf(4), attributes(5) NOTES
Some GSS mechanisms, such as kerberos_v5, provide their own authenticated-name-to-local-name (uid) mapping and thus do not usually have to be mapped using gsscred. See gsscred.conf(4) for more information. SunOS 5.10 11 Feb 2004 gsscred(1M)
All times are GMT -4. The time now is 07:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy