[Solved] Unable to mailx new $pid for a script restart


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Unable to mailx new $pid for a script restart
# 8  
Old 06-07-2013
OK. From the trace, it looks like we're close. It looks like your current invocation of mailx is something like:
Code:
   mailx -s "${SERVER} ${BATNAM} PID ${pid}" petey

and the problem you have is that mailx reads data from its standard input that will become the body of the message you're sending. In this case it is waiting for input instead of sending your message with an empty body (with the entire message being contained in the Subject field). To fix that, change the line to:
Code:
   mailx -s "$SERVER $BATNAM PID $pid" petey < /dev/null

In addition to adding the redirection (shown in red above), I also removed unneeded braces in the subject field. (The braces won't hurt anything, but they aren't needed in these three cases.) Because the mailx is hanging, the echo of the new PID to a new log file is not being run either. Adding the redirection to mailx will enable your script to create that new log file.

Unless you see some other problem, it looks like the only thing you haven't done yet is to change the else side of your if statement from:
Code:
   echo "service is ok"
   pid=""

to:
Code:
   echo "service is ok"

As I said before, setting pid to an empty string here doesn't hurt anything, but serves no purpose whatsoever (other than to make people who might read your script wonder why it is there).
# 9  
Old 06-10-2013
i will try tomorrow morning at work

thanks, i will try new suggestions, makes sense, i will implement as soon as i go in to work. thanks! ill let you know the results.

---------- Post updated 06-10-13 at 10:52 AM ---------- Previous update was 06-09-13 at 11:51 PM ----------

/dev/null redirection does not work...

also this script will be run as root, the backend db requires a user name that checks for proper creds to access it. I will fix that when the time comes to do crontab as root. However, what is happening is fine now. see below

script that works now:

Code:
# 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
PFDIR="/usr/script8/pf_files"           # pf dir
SERVER="PHANTOM"                        # servername here
SLOG="/usr/script8/batch/LOGS"          # log dir
SMAILER="petey"                         # person(s) to email

# export the vars
export BATDIR BATNAM BATPF PFDIR SERVER SLOG SMAILER

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

if [ "$pid" = "" ]
 then
  cd $BATDIR
  ./$BATNAM &
    $pid=$! # 2>/dev/null
      echo "$SERVER $BATNAM was restarted $pid=$! " \
      | mailx -s "$SERVER $BATNAM was restarted NEW PID $pid=$! " $SMAILER
       echo "NEW PID STARTED $pid=$! for $BATNAM on $SERVER" > "${SLOG}/${BATNAM}-restart-on--`date +%F-%T`"
exit 0
else
  echo "$pid=$!"
  echo "service is ok"
fi

sh -x results below:
Code:
$ sh -x fst-sig-restart.sh.final
+ BATDIR=/usr/script8/batch
+ BATNAM=bat_fstsi61c.sh
+ BATPF=bat_fstsi61.pf
+ PFDIR=/usr/script8/pf_files
+ SERVER=PHANTOM
+ SLOG=/usr/script8/batch/LOGS
+ SMAILER=petey
+ export BATDIR BATNAM BATPF PFDIR SERVER SLOG SMAILER
+ + ps -ef
+ awk -F  {print $2}
+ grep -v grep
+ grep bat_fstsi61.pf
pid=
+ echo

+ [  =  ]
+ cd /usr/script8/batch
+ ./bat_fstsi61c.sh
+ =21818
fst-sig-restart.sh.final[38]: =21818:  not found.
+ mailx -s PHANTOM bat_fstsi61c.sh was restarted NEW PID =21818  petey
+ echo PHANTOM bat_fstsi61c.sh was restarted =21818
+ echo NEW PID STARTED =21818 for bat_fstsi61c.sh on PHANTOM
+ + date +%F-%T
1> /usr/script8/batch/LOGS/bat_fstsi61c.sh-restart-on--2013-06-10-10:35:56
+ exit 0

mail sent and file created for log.

my issue is now the batch script this script runs.
the error is invalid user/pw blah blah. i'll fix that.

thanks for the suggestions guys, really, that helped and i learned a few new things.
THANKS!!!

you may close this one.

pete
ps ill be back Smilie i like your guys teaching style.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. 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
Login or Register to Ask a Question