Perl: FH and multiple writes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: FH and multiple writes
# 1  
Old 08-20-2008
Perl: FH and multiple writes

I found this logging subroutine on the net that I want to use but despite trying many things, I cannot figure out how to get the date in front of the logged text. Ideally what I'm looking for is a line that looks something like this:
Wed Aug 20 18:17:29 PDT 2008 - my logging info here.

my $logging= 1;
if($logging){open FILE , " >> ./my.log";}


sub logit{
if ($logging){
# print FILE system("date");
print FILE "$_[0]\n";
}
}

unless (system "/usr/bin/ssh -l username server hostname > /dev/null") {
logit("remote host available");
} else {
logit("remote host NOT available")
};

Any clues on this?

Thanks,
Gary
# 2  
Old 08-21-2008
replace this:
Code:
print FILE "$_[0]\n";

with:
Code:
print FILE scalar(localtime(time())), "$_[0]\n";

# 3  
Old 08-21-2008
Thank-you!

You make that look so easy.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

OpenBSM not catching all file writes

I have a custom auditing class configured for these events but it doesn't seem to be catching it when I do a "echo hey > test.txt" Any ideas on why that is? ---------- Post updated at 06:04 PM ---------- Previous update was at 05:47 PM ---------- Scratch this topic, it looks like it's because... (0 Replies)
Discussion started by: thmnetwork
0 Replies

2. Shell Programming and Scripting

Reading from a file a background program writes to

Hi! #!/usr/bin/env bash rm tmpcomm nc -v -u -l 444 | hexdump -b > tmpcomm while : do read l1 < tmpcomm read l2 < tmpcomm read l3 < tmpcomm read l4 < tmpcomm # do something doneI start netcat in the background and listen for an incoming conncetion. All incoming... (1 Reply)
Discussion started by: torax123
1 Replies

3. Solaris

Network writes contantly spiking in throughput

Hey guys First post... and im not exactly a solaris guru but here goes Ive setup a solaris 10 box with a raidz2 set of 6 disks... I have also setup Samba with open shares for some CIFs access... now my issue is that when i transfer large files to it the network performance contantly... (8 Replies)
Discussion started by: silicoon
8 Replies

4. Filesystems, Disks and Memory

Life span of HDD - maximum reads/writes etc

Hi All I was wondering how the copying of vast amounts of data affected the overall lifespan of an HDD. In my example, I'm copying approx 120GB (250,000) of files, once per hour from disk to another. Is this likely to have a detrimental effect on the disk in terms of reads/writes etc? ... (2 Replies)
Discussion started by: huskie69
2 Replies

5. Solaris

odd behaviour of app writes to mirrored volumes

Hi, Normally, I setup my volumes under Solaris (doesnt matter, 8 or 10), as vxassist -g dg01 -U gen make vol01 500m dg0101, then I do a mirror vxassist -g dg01 mirror vol01 dg0102. Which is legal and does work, however, when the primary dg01 array (or simply in this case, the volume)... (2 Replies)
Discussion started by: mrmurdock
2 Replies

6. UNIX for Advanced & Expert Users

Does sync(2) block writes until completed?

Gentle readers, I am trying to observe system behavior on our RHEL 5.2 machines. I notice that, it appears to me, based on random iterations of dd if=/dev/zero of=/var/tmp/bigfile bs=1024 count=20000 ...that if the pdflush is flushing buffers at the time of my write, my write will take... (4 Replies)
Discussion started by: mschwage
4 Replies

7. UNIX for Dummies Questions & Answers

which process writes to file

Some process rewrites a file ( i'm hacked :) Can I somehow monitor which process does that? (2 Replies)
Discussion started by: hachik
2 Replies

8. Shell Programming and Scripting

sh script that reads/writes based upon contents of a file

Hi everyone, Ive got a quick question about the feasibility and any suggestions for a shell script. I can use sh or ksh, doesnt matter. Basically, Ive got an output file from a db2 command that looks like so: SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL KEYS F4 F5 ... (3 Replies)
Discussion started by: rdudejr
3 Replies
Login or Register to Ask a Question