Any way for a perl script to know who called it and/or how?
Be it another script, or an executable. Straight from the command-line or the cron scheduler.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Tools to help track down how a Perl script was started:
getppidreturns parent process id. You can then usepsor/proc/<pid>to get more information about the calling process.$^X: full path to the perl interpreter, which may provide a clue about how Perl was started from the shell$0,__FILE__: name of the script invoked from the command line, and the current file name. If they are consistent, then the current file contains the script that was invoked from the command line.@ARGV: command line arguments passed to your script. With$^X,$0, and@ARGV, you know exactly how the Perl interpreter was started from the shell.caller: stack trace information. Ifcallerreturnsundefat the start of a script, then you are at the top frame of the stack, and your script was invoked from the shell. Otherwisecallerreturns the package, file, and line where your script was invoked (withdoorrequire).$^T: time (in seconds since the “epoch”) that the current Perl script was started, so you know when the current Perl interpreter was started from the shell. Usescalar localtime($^T)to see this value in a friendlier format.