Sponsored Content
Top Forums Shell Programming and Scripting Help scripting to start, check, and restart processes Post 302532979 by neutronscott on Thursday 23rd of June 2011 09:50:18 AM
Old 06-23-2011
Quote:
Originally Posted by MacG32
Thank you very much neutronscott for your help, this has worked like a charm. Looks like I was way off. Thanks again. Smilie
There's just many different ways it can be solved. Instead of keeping a PID file (my original trial) I just ask screen if the session is running. It makes it so elegant, eh? Smilie

Thanks for the Thanks! Smilie

---------- Post updated 06-23-11 at 09:50 AM ---------- Previous update was 06-22-11 at 02:13 PM ----------

Oh man, I couldn't sleep last night because I was thinking I didn't test all cases. So first thing today I run 'chkscreen' while attached to 'server1' session and I was right. bug Smilie

Sorry. Using '-r' checks if there is a session you can attach to, which is false if you're already attached.

So change

Code:
# does the session exist?
screen -r $SESSION -ls -q 2>&1 >/dev/null

to read

Code:
# does the session exist?
screen -S $SESSION -ls -q 2>&1 >/dev/null

And it shouldn't start extra servers when you're viewing the screen anymore. Sorry.
This User Gave Thanks to neutronscott For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I make a program start up automatically after the computer restart/startup?

hi all How can I make a program start up automatically after the computer restart/startup in fedora? something like: ... Establish a shell then run some of command code. Thanks for Help!! (1 Reply)
Discussion started by: munna_dude
1 Replies

2. Shell Programming and Scripting

need help: shell script to restart apache when no. of processes keeps growing

I need a shell script to kill apache and restart it, in case the number of processes keeps growing. The logic is like the below, but I don't know how to get the number and neither the syntax. Could somebody kindly help? if no_of_processes (ps ax ¦ grep httpd) > 200 then killall httpd... (14 Replies)
Discussion started by: _joshua_
14 Replies

3. AIX

How to start/stop/restart NFS on AIX

Hi, Very new to aix How to start/stop/restart NFS on AIX thanks, (2 Replies)
Discussion started by: jredx
2 Replies

4. UNIX for Advanced & Expert Users

Log 'syslog start/stop/restart' messages

How can I tell my syslog.conf to log "syslog start/stop/restart" messages on a Solaris box? (1 Reply)
Discussion started by: SunnyK
1 Replies

5. Shell Programming and Scripting

Start Stop Restart

I'm wondering how I should make a script that can start, stop, and restart another script. What I need to be able to do, is start and stop a perl script from the command line. The easiest way of doing this seems to be to have another script, starting and stopping the other script. I have BASH,... (7 Replies)
Discussion started by: Bakes
7 Replies

6. Shell Programming and Scripting

guarantee to start before restart...

Hi All, is there a way or script that i can check my AIX 5.3 OS will restart before i made restart? is there a script that can check all the startup files are ok before restarting. it is because i was stuck last time when i restart my PC because some startup files were missing:o. (2 Replies)
Discussion started by: malcomex999
2 Replies

7. Solaris

How to start/stop processes

Please anyone tell me In my last interview the HR asks me how to monitor, start,stop & kill the various processes and subprocesses. Please anyone explain me clearly. It's my personal request (3 Replies)
Discussion started by: suneelieg
3 Replies

8. UNIX for Dummies Questions & Answers

Stop/Start vs. Restart

Is there any functional difference between: issuing separate stop/start commands like this; super (handler) (instance) stop super (handler) (instance) start versus issuing a single recycle command like this; super (handler) (instance) restart (3 Replies)
Discussion started by: Newbix
3 Replies

9. Emergency UNIX and Linux Support

Check hung process and restart

Hi all I have networker running on a RHEL 5.7 and over time it hangs. So the solution backup team proposed is to check if the process is hung, to stop and start it. Unfortunately for me, the rc script only allows three commands, start, stop and status (no restart option) so I managed to set... (15 Replies)
Discussion started by: hedkandi
15 Replies

10. Red Hat

Service restart and check if running

Hello, I'l like to create a script that restart a service (/etc/init.d/httpd restart) and also check if after restart the service is actually running. Sometimes it happen that at the first try the service fails to restart. Thanks (2 Replies)
Discussion started by: bazzola
2 Replies
CEREAL-ADMIN(8) 					      Administration Commands						   CEREAL-ADMIN(8)

NAME
cereal-admin - administer cereal sessions SYNOPSIS
cereal-admin command [args] DESCRIPTION
cereal-admin is a program to administer cereal sessions. A cereal session is a special (restricted) screen(1) session attached to a serial terminal. Each cereal session is owned by a particular user (USER) who is allowed to "attach" to the cereal screen session and interact with the specified serial terminal via screen. Each cereal session is also associated with a particular log group (LOGGROUP) whose members are allowed to "follow" the logs of the session. Cereal was designed to monitor serial lines connected to the serial consoles of remote machines. The cereal system is outlined at: http://cmrg.fifthhorseman.net/wiki/cereal SUBCOMMANDS
cereal-admin takes various subcommands: create SESSION TTY BAUD USER LOGGROUP Create a new session named SESSION on tty TTY, with baud rate BAUD. USER is the user that will own the session, and LOGGROUP is the group that will be able to follow the session non-interactively (ie. read the logs). Once created, the session will be in a "stopped" state. `c' may be used in place of `create'. start [options] SESSION [SESSION]... Start session(s). For each session specified, the session directory is registered in the runsvdir directory. The screen session will be attached to the serial terminal and logging of the terminal will begin. `s' may be used in place of `start'. options: -a (--all) to enable all sessions. restart [options] SESSION [SESSION]... Restart session(s). This sends running sessions a "restart" signal, and starts session that are not running. This can be used when changes have been made to the screenrc, for instance. `r' may be used in place of `restart'. options: -a (--all) to disable all sessions, -r (--running) to restart just the currently running sessions. stop [options] SESSION [SESSION]... Stop session(s). This kills the screen session attached to the serial terminal by sending it an "exit" signal, and then unregister- ing the session directory from the runsvdir directory. `k' may be used in place of `stop'. options: -a (--all) to disable all ses- sions. destroy [options] SESSION [SESSION]... Destroy session(s) entirely. This will destroy the session directory, including all history of the session and the logs. `d' may be used in place of `destroy'. options: -a (--all) to remove all sessions. list [SESSION]... List session(s). With no arguments, will list all sessions. The leading three characters in the list indicate: whether the session is running (+) or not (-) or in some unknown state (?), whether the user can attach to the session (a) or not (-), whether the user can follow the session (f) or not (-). If the session state is unknown (?), it's usually because the user asking for information about the session can't read the session stat file. `l' may be used in place of `list'. help Output a brief usage summary. `h' or `?' may be used in place of `help'. LOGS
Logs are handled by svlogd. For information on how to control session log handling, please see svlogd(8) and/or log-limits.txt from the documentation of this package. FILES
/etc/cereal/screenrc Default cereal screenrc file. /etc/cereal/cereal-admin.conf Configuration file to set parameters for session creation and management. /var/lib/cereal/sessions/$SESSION/screenrc Special screenrc file for session SESSION. The presence of this file overrides the default screenrc file /etc/cereal/screenrc. EXIT STATUS
Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble. AUTHOR
Written by Jameson Rollins and Daniel Kahn Gillmor. BUGS
If the invoking user does not have read and execute access to the cereal session's supervise directory, `cereal-admin list' may not always indicate that session's status accurately. REPORTING BUGS
Report bugs to <cereal@fifthhorseman.net>. COPYRIGHT
Copyright (C) 2007 Jameson Rollins and Daniel Kahn Gillmor This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
cereal(1), screen(1), runsvdir(8), svlogd(8) cereal-admin 0.1 March 2007 CEREAL-ADMIN(8)
All times are GMT -4. The time now is 01:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy