And now it complains about this test if there is another instance of the Pidfile running:
Code:
root@comp:/directory/script# perl script.pl Can't locate object method "new" via package "Proc::Pidfile" (perhaps you forgot to load "Proc::Pidfile"?) at script.pl line 18.
---------- Post updated at 02:39 PM ---------- Previous update was at 09:57 AM ----------
So I added at Line 7:
Code:
use Proc::Pidfile;
...but now I get a different error. Wow I am really new at this...
Code:
root@comp:/directory/script# perl script.pl
Can't locate Proc/Pidfile.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at script.pl line 7.
BEGIN failed--compilation aborted at script.pl line 7.
---------- Post updated at 02:47 PM ---------- Previous update was at 02:39 PM ----------
Does this mean that something is not installed correctly in my perl distro (using Ubuntu Server 12.04 LTS)?
---------- Post updated 08-16-13 at 10:11 AM ---------- Previous update was 08-15-13 at 02:47 PM ----------
Ok nevermind,
Seems that I was using an HP-UX native Perl library on Ubuntu.
Corrected:
Code:
#must install libproc-pid-file-perl package
use Proc::PID::File;
my $pp = Proc::PID::File->new (pidfile => $RunFile) or die "Unable to create pidfile: $RunFile\n";
instead of:
Code:
use Proc::Pidfile;
#my $pp = Proc::Pidfile->new (pidfile => $RunFile) or die "Pidfile exists or can't be created: $!\n";
---------- Post updated at 01:57 PM ---------- Previous update was at 10:11 AM ----------
I am still not getting the desired output I guess. When the script runs, I am being told that my supervisor that the script will not create the file handle $OutfileH:
And I guess that is correct because I have to Ctrl-C out of it to get the following error:
Code:
root@comp:/directory/script# perl script.pl
^C print() on closed filehandle $OutfileH at script.pl line 28.
Line 28 being the following:
Code:
#Run the shell script through perl program
system( $RunScript, ">>/directory/logs/script.log 2>&1" ) == 0 or print $OutfileH &nicetime ."Script FAILED\n" or exit(1);
...
When the script runs, I am being told that my supervisor that the script will not create the file handle $OutfileH:
And I guess that is correct because I have to Ctrl-C out of it to get the following error:
Code:
root@comp:/directory/script# perl script.pl
^C print() on closed filehandle $OutfileH at script.pl line 28.
Line 28 being the following:
Code:
#Run the shell script through perl program
system( $RunScript, ">>/directory/logs/script.log 2>&1" ) == 0 or print $OutfileH &nicetime ."Script FAILED\n" or exit(1);
??
(1) But why do you Ctrl-C in the first place?
(2) Do you encounter that error because you press Ctrl-C? Or do you encounter it anyway?
(3) What happens if you let the script run its course? What do you see? Does it do what it is expected to do?
This User Gave Thanks to durden_tyler For This Post:
(2) Do you encounter that error because you press Ctrl-C? Or do you encounter it anyway?
Yes I press Ctrl-C because the script doesn't seem to finish.
Quote:
(3) What happens if you let the script run its course? What do you see? Does it do what it is expected to do?
Well I don't really see why it would take that long. I left it alone for a couple of hours and it was doing nothing.
I see that it creates the log entry and says that the script is being run. However it never exits.
---------- Post updated at 02:39 PM ---------- Previous update was at 02:33 PM ----------
Seems that by the time my script reaches Line 28, it doesn't open $OutfileH even though I am doing:
Interesting. I haven't seen your entire script and the "die" should've said something, but in any case:
- Print the value of $LogFile right before that "open" statement.
- Check that the path till the directory of the log file exists in your system.
- Check that you have the permission to create a file in that path.
This User Gave Thanks to durden_tyler For This Post:
Ok, much better.
I haven't used Proc::PID::File, so I can't say much about it.
However, consider the following lines in your code:
Quote:
Originally Posted by zixzix01
Here is my script as it stands now:
Code:
#!/opt/perl/bin/perl -w
...
...
close($OutfileH);
#Run the shell script through perl program
system( $RunScript, ">>/Directory/logs/script.log 2>&1" ) == 0 or print $OutfileH &nicetime ."Script FAILED\n" or exit(1); exit(0);
...
...
You close $OutfileH and then try to print to it if the shell script ($RunScript) fails. That will not work as Perl cannot write to a closed filehandle.
Also, assuming your Perl program is called "script.pl", the value of $LogFile would be "/Directory/logs/script.log", which is where you apparently want to redirect your shell script output. So, instead of hard-coding the log file name in the "system" command, use $LogFile.
Change the code to something like this:
Code:
open( $OutfileH, '>>', $LogFile)or die "Can't open $OutfileH: $!\n";
print $OutfileH &nicetime . ":Running script - " . $RunScript . "\n";
#Run the shell script through Perl program
system( $RunScript, ">>${LogFile} 2>&1" ) == 0 or print $OutfileH &nicetime ."Script FAILED\n";
close($OutfileH);
Finally, if you see the line containing "Running script" in your log file but nothing after it, then most likely your shell script is taking up a long time to run.
Try it out on its own first by executing the following command on the shell prompt:
Code:
/Directory/script/script.sh
You can also time it using the (surprise!) "time" command:
Code:
time /Directory/script/script.sh
See if the shell script's the bottleneck.
This User Gave Thanks to durden_tyler For This Post:
Linux System having all Perl, Python, PHP (and Ruby) installed
From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file
eg
eg
a Shell script run in a case statement call to run a php file, also Perl or/and Python file???
Like
#!/usr/bin/bash
....
....
case $INPUT_STRING... (1 Reply)
Hi,
I'm facing issues while trying to run a sample program on Linux.
If I try to run the script using the command "sh <filename.prog>", it doesn't work. But, if I try to execute it using the command "ksh <filename.prog>", it works fine.
Even ". ./filename.prog" works fine.
Can you... (6 Replies)
Hello
I am trying to run a python program using shell script, which takes a single argument from a file.
This file has one entry per line :
1aaa
2bbb
3ccc
4ddd
5eee
...
...
...
My shell script runs the program, only for the last entry :
#!/bin/sh
IFS=$'\n'
for line in $(cat... (2 Replies)
I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l)
here's the mode script:
#!/bin/sh
octal="$1"
shift
find . -maxdepth 1 -perm $octal -exec $@ {} \;
... (3 Replies)
Hi all
i have a unix script reformatter.sh
i have a process whereby this script reformats a file before a perl program is used to update it
i am having a little problem automating the entire process . is there a way whereby i can call the unix script from the perl program ? (12 Replies)
Hi,
I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me
Thanks (1 Reply)
Hello ,
I want to run some shell scripts in my perl script. I need to read the script's name from a file ( this file includes the name of all the scripts) and run the script one by one.. Please let me know how to go ..
Thanks in advance,
Radha (5 Replies)
suppose have different files
1.1
2.2
3.3
4.4
5.5
All the files have to run under the same command say
tr -d '\n'
so how to run all the files under the same command by using shell script (3 Replies)
Hi Perl/UNIX experts,
I have a problem in running a shell script from my perl script (auto.pl).
I run the perl script using
perl auto.pl
from the shell prompt
The shell script picks the files in "input" folder and procesess it.
The shell script blue.sh has this code.
export... (16 Replies)