Here u go for the srvtst26.pl rgds venkat
************************************************************************************************* #use diagnostics; use integer; #use File::Spec; use Socket; use FileHandle; ######################################## # Fork to create child daemon process # ######################################## unless ($pid = fork) { # Start of Child process setpgrp(0, $$); ######################################## # Define the Constant values # ######################################## use constant PROTOCOLNAME => "TCP"; use constant SRVPORTADDR => 5775; use constant RCVTIMEOUT => 10; use constant MAXRECVLENGTH => 4096; use constant QUEUELEN => 200; ######################################## # Define initial variables # ######################################## $LogOpen = "no"; ######################################## # Set Month and Weekday Lists # ######################################## @MonthList = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; @WeekDayList = qw/Sun Mon Tue Wed Thu Fri Sat/; ######################################## # Set Current Date and Time variables # ######################################## ($TimeSec, $TimeMin, $TimeHour, $Day, $MonthIdx, $Year, $WeekDay) = localtime(time); $Year += 1900; $Month = $MonthIdx + 1; # Create Save Date Using Day Month Year $SaveDate = ("$Day-$MonthList[$MonthIdx]-$Year"); # Create Save #### Temp for Testing #### #$SaveDate = ("$TimeHour-$Day-$MonthList[$MonthIdx]-$Year"); ######################################## # Main Body of the Program # ######################################## $DateTime = sprintf("%02d:%02d:%02d ${WeekDayList[$WeekDay]}-$Day-${MonthList[$MonthIdx]}-$Year", $TimeHour, $TimeMin, $TimeSec); write_log("AHD API Server - Start of Server Initialisation - $DateTime\n"); write_log("AHD API Server - Operating System Type is $^O\n"); ######################################## # Setup the Listen Server Port # ######################################## listenserver(*SERVERSOCKET, SRVPORTADDR, PROTOCOLNAME, QUEUELEN); ######################################## # Continually Process Client connects # ######################################## while(1) { ACCEPT_CONNECTIONS: ######################################## # Accept Client connections # ######################################## write_log("AHD API Server - Waiting on Acceptance of Client Connection\n"); unless ($Remote_Address = accept (CHILDSOCKET, SERVERSOCKET)) { write_log("AHD API Server - Client Accept Failure - $!\n"); redo ACCEPT_CONNECTIONS ; } $Remote_IP = inet_ntoa((unpack_sockaddr_in($Remote_Address))[1]); write_log("AHD API Server - Accepted Client Connection from IP = $Remote_IP\n"); autoflush CHILDSOCKET 1; ######################################## # Determine if data is ready # ######################################## write_log("AHD API Server - Now Doing Select\n"); $RBitsIn = ''; vec($RBitsIn, fileno(CHILDSOCKET), 1) = 1; select($RBitsOut = $RBitsIn, undef, undef, RCVTIMEOUT); if ($RBitsIn ne $RBitsOut) { write_log("AHD API Server - Client Receive Timeout of ".RCVTIMEOUT." seconds\n"); last ; } # sleep(3); ######################################## # Receive Client data # ######################################## write_log("AHD API Server - Now Receiving Data\n"); $rc = recv (CHILDSOCKET, $Buffer, MAXRECVLENGTH, 0); unless (defined $rc) { write_log("AHD API Server - Client Receive Failure - $!\n"); last ; } $Buffer = ("$Buffer\n"); write_log("AHD API Server - Buffer length = ".length($Buffer)."\n"); # print "Return Code = ${rc} \n"; # if (defined $rc) # { # write_log("Return code is Defined\n"); # } # # # # if ($rc eq '') # { # write_log("Return code is Null\n"); # } write_log("AHD API Server - Data = <<<$Buffer>>>\n"); # write_log(unpack('H354',"$Buffer")."\n"); #$Buffer = ("\$NX_ROOT/bin/bop_cmd -f \$NX_ROOT/site/mods/scripts/cradd08.frg \"newcr('null','INFO','4','5','null','AOD','#Infoman','-','Created from Infoman Record 19075340','null','null')\"\n"); # write_log("AHD API Server - Data2 = <<<$Buffer>>>\n"); # write_log(unpack('H354',"$Buffer")."\n"); # write_log("AHD API Server - Buffer length = ".length($Buffer)."\n"); ######################################## # Process the passed data # ######################################## call_ahd(); ######################################## # Check for null or empty Response data# ######################################## # unless (defined($RetBuffer)) if ($RetBuffer eq '') { write_log("AHD API Server - Null Response Data Received\n"); $RetBuffer = 'Null Response Data Received'; } ######################################## # Send back the Response data # ######################################## write_log("AHD API Server - Now Sending Response Data\n"); write_log("AHD API Server - Response Data=<<$RetBuffer>>\n"); # $RetBuffer = "Response Data"; unless (send (CHILDSOCKET, $RetBuffer, 0)) { write_log("AHD API Server - Client Send Response Failure - $!\n"); last ; } ######################################## # Receive Client data # ######################################## # write_log("AHD API Server - Now Re-receiving Data\n"); # # unless (recv (CHILDSOCKET, $Buffer, MAXRECVLENGTH, 0)) # { # write_log("AHD API Server - Client Re-receive Failure - $!\n"); # last ; # } # # write_log("AHD API Server - Data(2) = <<<$Buffer>>>\n"); ######################################## # Close Client connection # ######################################## write_log("AHD API Server - Now Closing Client Connection\n"); unless (close (CHILDSOCKET)) { write_log("AHD API Server - Client Close Connection Failure - $!\n"); # last ; } } ######################################## # Write Shutdown Msg and Print All Msgs# ######################################## write_log("AHD API Server - Now Shutting Down\n"); exit 0; ######################################## ######################################## ## Subroutines ## ######################################## ######################################## sub listenserver { ######################################## # Define the Local variables # ######################################## my ($SOCKETHANDLE, $Service_Name, $Protocol_Name, $Queue_Length) = @_; my ($Port_Number, $Socket_Type, $Protocol_Number, $Local_Socket); my ($Buffer, $RetBuffer); ######################################## # Determinee the Protocol number # ######################################## $Protocol_Number = (getprotobyname($Protocol_Name)) [2]; unless ($Protocol_Number) { write_log("AHD API Server - Couldn't find protocol $Protocol_Name\n"); return ; } else { write_log("AHD API Server - Protocol Number = $Protocol_Number\n"); } ######################################## # Determine the Port from Num or Name # ######################################## if ( $Service_Name =~ /^\d+$/) { $Port_Number = $Service_Name } else { $Port_Number = (getservbyname($Service_Name, $Protocol_Name))[2]; unless ($Port_Number) { write_log("AHD API Server - Can't find service $Service_Name"); return; } } ######################################## # Create a socket for the Server # ######################################## unless (socket($SOCKETHANDLE, PF_INET, SOCK_STREAM, $Protocol_Number)) { write_log("AHD API Server - Couldn't create socket: $!\n"); return ; } ######################################## # Set on local address reuse # ######################################## unless (setsockopt($SOCKETHANDLE, SOL_SOCKET, SO_REUSEADDR, 1)) { write_log("AHD API Server - Couldn't set socket options: $!\n"); return ; } ######################################## # Bind the socket for the Server # ######################################## $Local_Socket = sockaddr_in($Port_Number, INADDR_ANY); unless (bind($SOCKETHANDLE, $Local_Socket)) { write_log("AHD API Server - Failed to bind to socket: $!\n"); return ; } ######################################## # Listen for Connections # ######################################## write_log("AHD API Server - Listening for Connections\n"); unless (listen ($SOCKETHANDLE, $Queue_Length)) { write_log("AHD API Server - Couldn't listen on socket: $!\n"); return ; } return(1) ; } sub call_ahd { # Escape the '\' character $Buffer =~ s/\\/\\\\\\/g; write_log("AHD API Server - DataAfter1 = <<<$Buffer>>>\n"); # Escape the '$' character $Buffer =~ s/\$/\\\$/g; write_log("AHD API Server - DataAfter2 = <<<$Buffer>>>\n"); # Put $NX_ROOT back $Buffer =~ s/\\\$NX_ROOT/\$NX_ROOT/g; write_log("AHD API Server - DataAfter3 = <<<$Buffer>>>\n"); # Escape the '`' character $Buffer =~ s/\`/\\\`/g; write_log("AHD API Server - DataAfter4 = <<<$Buffer>>>\n"); $RetBuffer = `${Buffer} 2>&1`; # $RetBuffer = `${Buffer}`; # print ("#############\n"); # print ($RetBuffer); # print ("#############\n"); return(1) ; } sub write_log { my ($LogMsgs) = @_; ($TimeSec, $TimeMin, $TimeHour, $Day, $MonthIdx, $Year, $WeekDay) = localtime(time); $Year += 1900; $Month = $MonthIdx + 1; # Create Current Date Using Day Month Year $CurrentDate = ("$Day-$MonthList[$MonthIdx]-$Year"); # Create Current #### Temp for Testing #### #$CurrentDate = ("$TimeHour-$Day-$MonthList[$MonthIdx]-$Year"); # print ("Save Date is $SaveDate\n"); # print ("Current Date is $CurrentDate\n"); if ($CurrentDate ne $SaveDate) { # print ("Dates are not the same - Close Current LogFile\n"); close (LOGFILE); $LogOpen = "no"; } else { # print ("Dates are the same - No Action\n"); } if ($LogOpen ne "yes") { # print ("Open New Log File\n"); # Create Log File Name Using Year Month Day $LogFileName = sprintf("log/ahdxapi-%04d-%02d-%02d.log", $Year, $Month, $Day); # Temp Log File Name - for #### Testing #### # $LogFileName = sprintf("log/ahdxapi-%04d-%02d-%02d-%02d00.log", $Year, $Month, $Day, $TimeHour); # print ("New Log file Name is <$LogFileName>\n"); unless (open (LOGFILE, ">>$LogFileName")) { print ("Error openning Log file - $!\n"); exit (1); } autoflush LOGFILE 1; $LogOpen = "yes"; # Create Save Date Using Day Month Year $SaveDate = ("$Day-$MonthList[$MonthIdx]-$Year"); # Create Save #### Temp for Testing #### # $SaveDate = ("$TimeHour-$Day-$MonthList[$MonthIdx]-$Year"); } $LogBuffer = sprintf("%04d-%02d-%02d %02d:%02d:%02d $LogMsgs", $Year, $Month, $Day, $TimeHour, $TimeMin, $TimeSec); print (LOGFILE $LogBuffer); return(1); } } # End of child Process } # Continue of Parent Process { print ("#############\n"); print ("Child daemon Process started - Initiator now ending\n"); print ("#############\n"); exit if $pid; } *********************************************************************************************************** -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, 2 July 2003 12:02 PM To: Vema Venkata Subject: RE: [Perl for Beginners] RE: Welcome to perlforbeginners me from chennai but niow working in bang.. and u ?? Have Fun Reuben Masil 98861 06319 A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing. -George Bernard Shaw -----Original Message----- From: Vema Venkata [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 02, 2003 12:00 PM To: D Reuben Masilkumar Gnanamani-OP Subject: RE: [Perl for Beginners] RE: Welcome to perlforbeginners dude, i appoligies for this.it is not perl it is shell BTW which part ur from? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, 2 July 2003 11:58 AM To: Vema Venkata Subject: RE: [Perl for Beginners] RE: Welcome to perlforbeginners Which ver of perl is this.. ?? Have Fun Reuben Masil A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing. -George Bernard Shaw -----Original Message----- From: Vema Venkata [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 2:41 PM To: [EMAIL PROTECTED] Subject: [Perl for Beginners] RE: Welcome to perlforbeginners ------------------------------------------------------------------------ You cannot reply to this message via email because you have chosen not to disclose your email address to the group. To reply: http://groups.yahoo.com/group/perlforbeginners/post?act=reply&messageNum=404 ------------------------------------------------------------------------ For the following script can any one help me to create a log file wud be appreciated help asap rgds venkat ******************************************************************************************************************************* xapipgm=srvtst26.pl pgrep -f $xapipgm > /dev/null # runrc=$? # echo "Return Code is: $?" if [ $? -eq 0 ] then set `pgrep -f $xapipgm ` echo "AHD XAPI Server ($xapipgm) Running with Process Id: $1" else echo "AHD XAPI Server is now Started Running." set `date '+%Y %m %d %H %M' ` xapipgm=srvtst26.pl #echo "log: log/init/ahdxapi.init.$1$2$3.$4$5.log" #echo "err: log/init/ahdxapi.init.$1$2$3.$4$5.err" perl -w $xapipgm >log/init/ahdxapi.init.$1$2$3.$4$5.log 2>log/init/ahdxapi.init.$1$2$3.$4$5.err perl -w $4$5>log/init/ahdxapi.init fi *********************************************************************************************** -----Original Message----- From: perlforbeginners Moderator [mailto:[EMAIL PROTECTED] Sent: Tuesday, 1 July 2003 2:35 PM To: Vema Venkata Subject: Welcome to perlforbeginners Hello, Welcome to the perlforbeginners group at Yahoo! Groups, a free, easy-to-use email group service. Please take a moment to review this message. To learn more about the perlforbeginners group, please visit http://groups.yahoo.com/group/perlforbeginners To start sending messages to members of this group, simply send email to [EMAIL PROTECTED] If you do not wish to belong to perlforbeginners, you may unsubscribe by sending an email to [EMAIL PROTECTED] To see and modify all of your groups, go to http://groups.yahoo.com/mygroups Regards, Moderator, perlforbeginners Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ ------------------------ Yahoo! Groups Sponsor ---------------------~--> Get A Free Psychic Reading! Your Online Answer To Life's Important Questions. http://us.click.yahoo.com/Lj3uPC/Me7FAA/ySSFAA/ndFolB/TM ---------------------------------------------------------------------~-> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ DISCLAIMER: This message contains privileged and confidential information and is intended only for the individual named.If you are not the intended recipient you should not disseminate,distribute,store,print, copy or deliver this message.Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted,corrupted,lost,destroyed,arrive late or incomplete or contain viruses.The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. DISCLAIMER: This message contains privileged and confidential information and is intended only for the individual named.If you are not the intended recipient you should not disseminate,distribute,store,print, copy or deliver this message.Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted,corrupted,lost,destroyed,arrive late or incomplete or contain viruses.The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]