file handle and variable issues...

E

erik

I am using expect to get firewall configs and then write them to a FH.
My issue is the I cannot get the $date to work within the FH, therefore
it does not write the file.

Here is my subfunction:

#############################################################
sub write_config{

$date = qx(date +%x);

$date =~ s/\//-/g;

print " THE DATE IS: $date";

#qx(touch /vault/var/ns-config/ns-$date/$device-$date);

qx(mkdir /vault/var/ns-config/$date/);

$filename = "/vault/var/ns-config/$date/$device";


open(IN, ">$filename") || die ("Open Failed: $!\n");

print IN "$config_capture\n";

sleep 3;

#qx(/bin/gzip /vault/var/ns-config/$date/$device-$date);

};#end sub
############################################################

At run time, I get this...

THE DATE IS: 11-13-2005
mkdir: cannot create directory `/vault/var/ns-config/11-13-2005': File
exists
sh: line 1: /: is a directory
Open Failed: No such file or directory

The mkdir error is expected because I have run this many times. You can
disregard that. But the issue appears to be an issue with $date in the
$filename variable.

If I change $filename from the original $filename =
"/vault/var/ns-config/$date/$device";

to

$filename = "/vault/var/ns-config/11-13-2005/$device";

It works fine. What is wrong with $date in this context?
 
B

Brian Wakem

erik said:
I am using expect to get firewall configs and then write them to a FH.
My issue is the I cannot get the $date to work within the FH, therefore
it does not write the file.

Here is my subfunction:

#############################################################
sub write_config{

$date = qx(date +%x);

$date =~ s/\//-/g;

print " THE DATE IS: $date";

#qx(touch /vault/var/ns-config/ns-$date/$device-$date);

qx(mkdir /vault/var/ns-config/$date/);

$filename = "/vault/var/ns-config/$date/$device";


open(IN, ">$filename") || die ("Open Failed: $!\n");
sh: line 1: /: is a directory
Open Failed: No such file or directory


What is in $device? Perhaps nothing? Therefore you are trying to
open /vault/var/ns-config/13-11-2005/, which is a directory?
 
A

A. Sinan Unur

Why spawn an external process when it is simple to do it in Perl?

use POSIX qw( strftime );
print strftime(q{%d-%m-%Y}, localtime), "\n";

perldoc -f mkdir

Make sure to check if the call actually succeeded.
What is in $device? Perhaps nothing? Therefore you are trying to
open /vault/var/ns-config/13-11-2005/, which is a directory?

Ditto.

Sinan
 
E

erik

But if I hard code the $date in the $filename, it works fine. That part
I can't explain.
 
E

erik

I also printed out the $device as you inquired about.

print " THE device IS: $device";

It prints minnesota-ns. I don't think the $device is the issue though,
it is something with using that dash seperated $date variable in a FH.
 
M

Matt Garrish

erik said:
But if I hard code the $date in the $filename, it works fine. That part
I can't explain.

What the hell are you talking about? If you don't learn to quote some
context to your messages soon you're not going to find anyone who'll help
you.

Matt
 
A

A. Sinan Unur

What the hell are you talking about? If you don't learn to quote some
context to your messages soon you're not going to find anyone who'll
help you.

erik is already in my killfile, I am only following this thread through
others replies to it. What can I say: I am bored today.

If erik were to realize that the external date command has a newline at
the end, erik might either chomp the string returned by date, or wisen
up, and actually use the method I posted earlier to construct the date
string in Perl.

But, sometimes, that is too much to ask of people, apparently.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top