Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Looking for script running before I run script again Post 302630309 by neutronscott on Wednesday 25th of April 2012 04:47:14 PM
Old 04-25-2012
Code:
pidfile=/var/tmp/stats.pid

# exit if another is running
[ -e "$pidfile" ] && exit

# create pid file
echo $$ >"$pidfile"

# delete pid file on exit (may have to do this definitely depending on shell)
trap "rm $pidfile" EXIT

These 2 Users Gave Thanks to neutronscott For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies

2. Shell Programming and Scripting

Script not running properly when run from Crontab

Hi I am a novice Linux/Perl user and am struggling to overcome what I am sure is a simple problem. I am using a perl program to create a shell script daily containing between 10 and 30 "at -f" commands for the same day. Then I change the file attributes to allow the file to be executed. When... (2 Replies)
Discussion started by: simoncjones
2 Replies

3. Shell Programming and Scripting

[Solved] Help with running ps -e | less on nano script editor

p { margin-bottom: 0.08in; } This is just a portion of a script I'm writing on Linux nano script editor. When I run the script I get stuck on the ps -e | less command portion of the script:wall:. It displays all the process running but it does not allow me to move to the next line on the script.... (2 Replies)
Discussion started by: SANA4SPA
2 Replies

4. Shell Programming and Scripting

Run perl command in script[solved]

Hi all, When I put the Perl command in a script, I got error. system("perl -pi -e 's@words@words@g' myFile"); The error is: Unrecognized character \x8A; marked by <-- HERE after دت مد�<-- HERE near column 15 at -e line 1. Thanks in advance. ---------- Post updated at 06:30 AM... (0 Replies)
Discussion started by: Lham
0 Replies

5. Shell Programming and Scripting

run shell script under nohup directly [solved]

Hi, i am not able to run the loop in nohup directly. nohup 'for i in $(seq 10); do echo $i;./mscript.sh $i; done' can some one help me how to run this directly in nohup? ---------- Post updated 03-15-12 at 12:20 AM ---------- Previous update was 03-14-12 at 11:59 PM ---------- From... (0 Replies)
Discussion started by: johninweb
0 Replies

6. UNIX for Dummies Questions & Answers

[Solved] How to Check if a script is running?

Hi All, I am new to Unix... Can you please let me know how we can check if a script is running or not on Solaris box? (4 Replies)
Discussion started by: Rahul466
4 Replies

7. Shell Programming and Scripting

[Solved] The SCRIPT command - Can we see the log file of a running session?

Hello. This is my situation. script .anything ls -l . ---How can I see the content of .anything using (i.e) cat .anything? If not possible can someone suggest a sequence to simulate a console-recorder to "observ" from a RUNNING script session? Thanks Paolo Please use code tags... (3 Replies)
Discussion started by: paolfili
3 Replies

8. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

9. Shell Programming and Scripting

[Solved] Running a R script with in a shell script

Hi, I do have an R script named KO.R. Basically reads thousands of files, whose name has a pattern that differs at a portion of the file name, List.txt. Row_file1_mile.txt Row_file2_mile.txt Row_file3_mile.txt ... ... Row_file1000_mile.txt Below is a portion of my Rscript that reads... (4 Replies)
Discussion started by: Kanja
4 Replies
Control(3pm)						User Contributed Perl Documentation					      Control(3pm)

NAME
App::Control - Perl module for apachectl style control of another script or executable SYNOPSIS
use App::Control; my $ctl = App::Control->new( EXEC => $exec, ARGS => @args, PIDFILE => $pidfile, SLEEP => 1, VERBOSE => 1, ); my $pid = $ctl->pid; if ( $ctl->running ) { print "$pid is running "; } else { print "$pid is not running "; } # or alternatively ... print $ctl->status; $ctl->start; # or alternatively ... $ctl->cmd( 'start' ); $ctl->stop; $ctl->hup; $ctl->restart; DESCRIPTION
App::Control is a simple module to replicate the kind of functionality you get with apachectl to control apache, but for any script or exe- cutable. There is a very simple OO interface, where the constructor is used to specify the executable, command line arguments, and pidfile, and various methods (start, stop, etc.) are used to control the executable in the obvious way. The module is intended to be used in a simple wrapper control script. Currently the module does a fork and exec to start the executable, and sets the signal handler for SIGCHLD to 'IGNORE' to avoid zombie processes. CONSTRUCTOR
The constructor is called with a hash of options in the standard way. The options are as follows: EXEC Path to the executable to be controlled. This option is REQUIRED. ARGS Command line arguments for the executable. This option is OPTIONAL, but if set, should be an ARRAY reference. PIDFILE Path to the pidfile for the executable. This need not exists, but the constructor will die if it thinks it can't create it. If the path where the pidfile lives doesn't exist the constructor will try to create it. This option is REQUIRED. IGNOREFILE The ignore file allows you to temporarily disable the control functionality. Suppose you have a chkdaemon / crontab entry that restarts a service; specifying an IGNOREFILE means that you can disable this wihtout having to edit the relevant config files. CREATE_PIDFILE By default, App::Control depends on the application to manage the pid file. This is consistent will analogous utilities (apachectl, chk- daemon, etc.), but if you would like App::Control to create and remove pid files for you, then set this option to a true value. SLEEP Number of seconds to sleep before checking that the process has been started. If the start fails, the control script will loop with a SLEEP delay per iteration until it has (see <"LOOP">). Default is 1 second. head2 LOOP Number of times to loop before giving up on starting the process. VERBOSE If set to a true value, the module will output verbose messages to STDERR. METHODS
start Start the executable specified in the constructor. This method waits until it is convinced that the executable has started. It then writes the new pid to the pidfile. stop Stop the executable specified in the constructor. It assumes that the pid listed in the pidfile specified in the constructor is the process to kill. This method waits until it is convinced that the executable has stopped. hup Send a SIGHUP to the executable. restart Basically; stop if running, and then start. status Returns a status message along the lines of "$exec ($pid) is / is not running". cmd All of the above methods can also be invoked using cmd; i.e.: $ctl->start; is equivilent to: $ctl->cmd( 'start' ); give or take a call to AUTOLOAD! pid Returns the current value of the pid in the pidfile. running returns true if the pid in the pidfile is running. AUTHOR
Ave Wrigley <Ave.Wrigley@itn.co.uk> COPYRIGHT
Copyright (c) 2001 Ave Wrigley. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2003-08-27 Control(3pm)
All times are GMT -4. The time now is 05:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy