Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System call with user inputting values?

Status
Not open for further replies.
Apr 22, 2008
10
IE
Hi

I want Perl to make a system call to nfdump. nfdump has a specifc command list. Here is an example.

nfdump -R /../../ -t YYYY/MM/DD.09:00:00-YYYY/MM/DD.10:00:00

does anyone no how I can use system call to do this? But I also need to keep the Year Month and Day variables changeable.

Sorry if my posting is not up to standard this is my first post....!!

Thanks!!
 
Set variables for the date(s) and make the call using those variables. Put the command inside of back ticks (not single quotes).

Code:
$Date1 = "2008/04/05";
$Date2 = "2008/04/06";

`nfdump -R /../../ -t $Date1.09:00:00-$Date2.10:00:00`;
 
Since you are accepting user inputs as parameter to command, you may want to valicate the user input before passing them to command.

Code:
$date1 = $ARGV[0] ;
$date2 = $ARGV[1] ;

if ( ( $date1 =~ /^\d{4}\/\d{2}\/\d{2}$/ ) && ( $date2 =~ /^\d{4}\/\d{2}\/\d{2}$/) )
{
#run the command
}

else
{
#user input not valid
}

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Hi again..

Thanks for the quick replys and they really helped me sort out my problems..

another question...i have a program that can read files and print their extension. I need to extract information from this extension is there a way to do this?

Example: nfcapd.200803052325

I need to get .20080305 part of the extension.

any ideas?
 
It seems you need to find out first nine charactres, (probably a date part..), including a dot character.

Have a look at Perl substr() function.




--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
I would use split.

$data = 'nfcapd.200803052325';
@tmp = split(/\./, $data);
print "$tmp[1]\n";

To get the char's. Then substring to get the parts of it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
foreach $file(@filenames){

my(undef,undef,$ftype) = fileparse($file,qr{\..*});
print "$ftype\n";
#$data = 'nfcapd.200803052325';
@tmp = split(/\./,$ftype);
print "$tmp[1]\n";
$var = substr($tmp[1],0,8);
$year = substr($tmp[1],0,3);
$month = substr($tmp[1],4,5);
$day = substr($tmp[1],6,7);
print"$var:$year-$month-$day";

}

#########~~Sample from OUTPUT~~############
#200803052350
#20080305:200-03052-052350.200803052355
#200803052355
#20080305:200-03052-052355.200803211010
#200803211010
#20080321:200-03211-211010.200803280924
#200803280924
#############################################

It is probably something that i am doing wrong but this just does not seem to be going my way.

Any other suggestions?

 
You have your substr wrong. The first number is the character to start on, the second number is how many characters to get.
So year would start at 0, and you want 4. Month would start at 4 and you want 2, day start's at 6 and you want 2.

make sense?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
That is working way better....
Some more tweaking and il get it.

Thanks alot guys...I must say since i have joined this form the quick responses and accuracy of the replays are outstanding!!

Thanks again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top