Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Unable to mailx new $pid for a script restart Post 302817861 by olyanderson on Thursday 6th of June 2013 03:02:02 PM
Old 06-06-2013
[Solved] Unable to mailx new $pid for a script restart

Ill try to make this brief:

I am trying to get the script below to run another script defined as BATNAM.
The script runs fine, does what i designed it to do, however...

I would like it to mailx the NEW $pid that was restarted.

This script is supposed to go in crontab as root, and run by the min checking if $pid exists.

Lastly, should i try a diff approach, maybe a "while" or "until"? rather than "if/then/else"

I have tried sleep 10, as it does take more than 7 seconds for the script to show up in ps -ef|grep myusername.

could you pls review the code below, and make suggestions.
This is a simple syntax issue and I am unable to find it.

I am on hpux / /usr/bin/sh, and I have root if necessary.

thanks!
Code:
#!/usr/bin/sh -x
# set the locals
stty intr '^c'

# set the vars
BATDIR="/usr/script8/batch"             # batch dir
BATNAM="bat_fstsi61c.sh"                # batch process file
BATPF="bat_fstsi61.pf"                  # batch to grep
BATSVC="SIGTEST"                        # mail topic
BATPF="bat_fstsi61.pf"                  # batch to grep
SERVER="PHANTOM"                        # servername here
SDIR="/apps/sigmon/dvl/fst61"           # sigmon dir
SIN="$SDIR/in"                          # in dir
SPROC="$SDIR/proc"                      # proc dir
SLOG="/usr/script8/batch/LOGS"          # log dir
SMAIL="/usr/script8/batch/EMAILS"       # email log dir
SMAILER="petey"                         # person(s) to email

# export the vars
export BATDIR BATNAM BATSVC BATPF SERVER SDIR SIN \
SPROC SLOG SMAIL SMAILER

pid=`ps -ef|grep "$BATPF" |grep -v grep |awk -F" " '{print $2}'`
 echo $pid

if [ "$pid" = "" ]
 then
   /usr/bin/sh $BATDIR/$BATNAM
   sleep 10
   mailx -s "${SERVER} ${BATNAM} restarted" petey
   sleep 10
   echo "$pid" > $SLOG/"$BATNAM-restart-on--`date +%F-%T`"
 else
   echo "service is ok"
   pid=""
fi


Last edited by olyanderson; 06-06-2013 at 04:57 PM.. Reason: got it, thanks. ill use from now one, im new here
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

unable to do mailx from shell script

Hi From within a shell script my mailx doesnt seem to work...can somebody tell me what is wrong... #!/bin/ksh #Script to verify wheather all databases listed are up and running #Script works with Oracle8 and above databases #Script has to be run by ./scriptname DBA=xiamin@unix.com echo... (3 Replies)
Discussion started by: xiamin
3 Replies

2. Linux

mailx: Unable to send Japanese

Hi All, I am facing problem in sending Japanese characters using mailx command in GNU linux machine. The mail is going with junk characters like "メールの-界へようこそ". I tried changing the LANG value to japan locale off UTF-8. But it doesn't worked. I have to send the data as body not as an... (0 Replies)
Discussion started by: Karteek
0 Replies

3. Solaris

Unable to send mail through mailx

Hi, I am using solaris 5.9 OS and I am facing an issues with mailx. My SMTP port is configured to listen 6190 and not the default one which is 25. I can send mail to my inbox when i do it manually through the following steps root@<dbname> # telnet 15.12.88.10 6190 Trying 15.12.88.10...... (0 Replies)
Discussion started by: Srinathkiru
0 Replies

4. HP-UX

[Solved] mailx : unknown user issue

Hi all, I know this issues has been discussed multiple times, i have gone through many such discussion but unfortunately i am still not able to solve the issue being faced. I have configured the sendmail.cf with the smtp host name (Editing the entry starting with DS...) Post that restarted... (7 Replies)
Discussion started by: chpsam
7 Replies

5. Shell Programming and Scripting

[Solved] Unable to call a python script from bash

Hi, I am trying to run a python script embedded in bash script. But is throwing me an error. Please help. Script: #!/bin/bash nohup /usr/bin/python /opt/web/http.py & Error: /usr/bin/python: can't open file '/opt/web/http.py': No such file or directory Please help me on this. (6 Replies)
Discussion started by: maddy26615
6 Replies

6. Red Hat

Can't stop/restart postfix - pid associated with another process

This issue could happen to any other service but in this case its commssioning Postfix - it seems i can't stop postfix as the PID relates to another service - i've delete the 'master.lock' but to no available - any ideas, memeory commands etc ? thanks in advance ps. the serve is in Production so... (2 Replies)
Discussion started by: stevie_velvet
2 Replies

7. Shell Programming and Scripting

Unable to get pid from fuser

bash-3.2$ fuser -f /bin/nohup.out /bin/nohup.out: 13136o 13111o The pid is 13136. Can you tell me how can i extract just the pid 13136 from the above output ? bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v I was trying on this lines but i get strange... (3 Replies)
Discussion started by: mohtashims
3 Replies
service(8)						      System Manager's Manual							service(8)

NAME
service - run a System V init script SYNOPSIS
service SCRIPT COMMAND [OPTIONS] service --status-all service --help | -h | --version DESCRIPTION
service runs a System V init script in as predictable an environment as possible, removing most environment variables and with the current working directory set to /. The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of COMMAND depend on the invoked script. service passes COMMAND and OPTIONS to the init script unmodified. All scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start com- mand. service --status-all runs all init scripts, in alphabetical order, with the status command. EXIT CODES
service calls the init script and returns the status returned by it. FILES
/etc/init.d The directory containing System V init scripts. ENVIRONMENT
LANG, TERM The only environment variables passed to the init scripts. SEE ALSO
/etc/init.d/skeleton, update-rc.d(8), init(8), invoke-rc.d(8). Jan 2006 service(8)
All times are GMT -4. The time now is 09:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy