Sponsored Content
Top Forums Shell Programming and Scripting Perl program to run a Shell script issues... Post 302844137 by zixzix01 on Friday 16th of August 2013 04:10:47 PM
Old 08-16-2013
Here is my script as it stands now:

Code:
#!/opt/perl/bin/perl -w  

# Using recommended pragmas 
use strict; 
use warnings;  

#must install libproc-pid-file-perl package 
use Proc::PID::File; 
use File::Basename;  

my $Directory = "/Directory"; 
my $LogFile   = $Directory . "/logs/" . basename($0, ".pl") . ".log"; 
my $RunFile   = $Directory . "/logs/" . basename($0, ".pl") . ".run"; 
my $RunScript = $Directory . "/script/script.sh";  

my $OutfileH; #Output Handle  

# Make sure another instance isn't already running 
my $pp = Proc::PID::File->new (pidfile => $RunFile) or die "Unable to create pidfile: $RunFile\n";  
print $LogFile 
open( $OutfileH, '>>', $LogFile)or die "Can't open $OutfileH: $!\n"; 
print $OutfileH &nicetime . ":Running script - " . $RunScript . "\n"; 
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);  

#Functions 
########################################################################## 
sub nicetime {    
my ( $sec, $min, $hour, $mday, $mon, $year, $yday, $isdst ) = localtime(time);    
my $timestr = sprintf "%4d-%02d-%02d %02d:%02d:%02d", $year + 1900, $mon + 1, $mday, $hour, $min, $sec;    
return $timestr; 
}

---------- Post updated at 04:10 PM ---------- Previous update was at 04:05 PM ----------

The path to the Log files is definitely there as i can see the log file logging a script start:
Quote:
root@comp:/Directory/logs$ cat script.log
2013-08-16 09:44:04:Running script - /Directory/script/script.sh
2013-08-16 09:53:35:Running script - /Directory/script/script.sh
2013-08-16 09:54:57:Running script - /Directory/script/script.sh
2013-08-16 11:46:49:Running script - /Directory/script/script.sh
2013-08-16 13:30:40:Running script - /Directory/script/script.sh
2013-08-16 13:43:31:Running script - /Directory/script/script.sh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

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)
Discussion started by: hifake
16 Replies

2. Shell Programming and Scripting

want to run different files under the same program using shell script

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)
Discussion started by: cdfd123
3 Replies

3. Shell Programming and Scripting

Run shell program in perl

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)
Discussion started by: s123.radha
5 Replies

4. Shell Programming and Scripting

How to run perl code within a shell script...?

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)
Discussion started by: vijay_0209
1 Replies

5. Shell Programming and Scripting

Can you run a unix script from a perl program

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)
Discussion started by: dwightja24
12 Replies

6. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

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)
Discussion started by: computethis
3 Replies

7. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

8. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

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)
Discussion started by: ad23
2 Replies

9. Shell Programming and Scripting

Issues while trying to run a shell script using the command sh <filename.prog>

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)
Discussion started by: venkatesh17
6 Replies

10. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

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)
Discussion started by: hoyanet
1 Replies
BAK2DB.PL(8)						      System Manager's Manual						      BAK2DB.PL(8)

NAME
bak2db.pl - Directory Server perl script for restoring a backup SYNOPSIS
bak2db.pl -a archivedir [-Z serverID] [-D rootdn] { -w password | -w - | -j filename } [-t dbtype] [-n backendname] [-P protocol] [-v] [-h] DESCRIPTION
Restores a database from a backup. The Directory Server must be started prior to running this script. OPTIONS
A summary of options is included below: -a archivedir The directory of the archived database. -Z Server Identifier The server ID of the Directory Server instance. If there is only one instance on the system, this option can be skipped. -D Root DN The Directory Manager DN, or root DN. If not specified, the script will search the server instance configuration for the value. -w password The rootdn password. -w - Prompt for the rootdn password. -j password filename The name of the file that contains the root DN password. -t database type The backend database type (default: ldbm database). -n Backend Name The name of the LDBM database to restore. Example: userRoot -P Protocol The connection protocol to connect to the Directory Server. Protocols are STARTTLS, LDAPS, LDAPI, and LDAP. If this option is skipped, the most secure protocol that is available is used. For LDAPI, AUTOBIND is also available for the root user. -v Display verbose ouput -h Display usage EXAMPLE
bak2db.pl -a /LDAP/backups/20130305/ -D 'cn=directory manager' -w password -n userRoot -P LDAPS Note: security must be enabled to use protocol LDAPS. If LDAPS is not available it will default to next strongest/available proto- col automatically. bak2db.pl -a /LDAP/backups/20130305/ -Z instance2 -w password -n example -P LDAPI DIAGNOSTICS
Exit status is zero if no errors occur. Errors result in a non-zero exit status and a diagnostic message being written to standard error. AUTHOR
bak2db.pl was written by the 389 Project. REPORTING BUGS
Report bugs to http://bugzilla.redhat.com. COPYRIGHT
Copyright (C) 2013 Red Hat, Inc. Mar 5, 2013 BAK2DB.PL(8)
All times are GMT -4. The time now is 05:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy