Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Unable to mailx new $pid for a script restart Post 302818409 by olyanderson on Friday 7th of June 2013 12:55:36 PM
Old 06-07-2013
opps, double post, removed... for obvious reasons

---------- Post updated at 09:55 AM ---------- Previous update was at 09:47 AM ----------

well said don, thanks. i like your style.
here is a rewrite:

I have a script that will not show the current pid.

the script below uses a simple if statement.

the if statement is suppose to restart another process (it does!)

once the 2 script is restarted ( it stopped, this script restarts it)
it produces a pid.

it did NOT have a pid, thus needed to be restarted.
This script below does that.

problem: i can not grep/grab/whatever you want to call it, and mailx that new pid.

that's my problem: can NOT grab the new pid.

I am at work now, i will try your suggestion:
pid=$!

***sh -x stdout BEFORE i kill pid to simulate it's not running***



Code:
$ sh -x sig-ps-restart7.sh
+ stty intr ^c
+ BATDIR=/usr/script8/batch
+ BATNAM=bat_fstsi61c.sh
+ BATPF=bat_fstsi61.pf
+ BATSVC=SIGTEST
+ BATPF=bat_fstsi61.pf
+ SERVER=PHANTOM
+ SDIR=/apps/sigmon/dvl/fst61
+ SIN=/apps/sigmon/dvl/fst61/in
+ SPROC=/apps/sigmon/dvl/fst61/proc
+ SLOG=/usr/script8/batch/LOGS
+ SMAIL=/usr/script8/batch/EMAILS
+ SMAILER=petey
+ export BATDIR BATNAM BATSVC BATPF SERVER SDIR SIN SPROC SLOG SMAIL SMAILER
+ + ps -ef
+ grep bat_fstsi61.pf
+ grep -v grep
+ awk -F  {print $2}
pid=20599
+ echo 20599
20599
+ [ 20599 =  ]
+ echo service is ok
service is ok
+ pid=

*** sh -x stdout AFTER i kill pid to simulate it's not running ***

first i kill the current pid that is already running prior:


Code:
kill 20599

Code:
$ sh -x sig-ps-restart7.sh
+ stty intr ^c
+ BATDIR=/usr/script8/batch
+ BATNAM=bat_fstsi61c.sh
+ BATPF=bat_fstsi61.pf
+ BATSVC=SIGTEST
+ BATPF=bat_fstsi61.pf
+ SERVER=PHANTOM
+ SDIR=/apps/sigmon/dvl/fst61
+ SIN=/apps/sigmon/dvl/fst61/in
+ SPROC=/apps/sigmon/dvl/fst61/proc
+ SLOG=/usr/script8/batch/LOGS
+ SMAIL=/usr/script8/batch/EMAILS
+ SMAILER=petey
+ export BATDIR BATNAM BATSVC BATPF SERVER SDIR SIN SPROC SLOG SMAIL SMAILER
+ + ps -ef
+ grep bat_fstsi61.pf
+ grep -v grep
+ awk -F  {print $2}
pid=
+ echo

+ [  =  ]
+ cd /usr/script8/batch
+ pid=3951
+ mailx -s 'PHANTOM' 'bat_fstsi61c.sh' PID '3951' was started petey
+ . bat_fstsi61c.sh
trunc'd......
+ exec /apps/dlc/bin/our-data-base-here -b -p /tmp/job003954 -pf /usr/script8/pf_files/bat_fstsi61.pf

it appears to work for the pid part thanks!!!

BUT... it now needs to close: here is the ps -ef|grep petey


Code:
petey  3952  3944  0 09:29:49 pts/tt    0:00 mailx -s 'PHANTOM' 'bat_fstsi61c.sh' PID '3951' was started petey
  petey  3944 29979  0 09:29:49 pts/tt    0:00 sh -x sig-ps-restart7.sh
  petey 24556 24555  0  Jun  4  pts/tr    0:00 -sh
  petey  3951  3944  0 09:29:49 pts/tt    0:02 /apps/dlc/bin/our-data-base-here -b -p /tmp/job003954 -pf /usr/script8/pf_files/bat_fstsi61.pf

so now, this job will be put into a cron job, IF i we can make the mailx actually finish.. it seems to be sitting there ...

sorry had to leave other script for security reasons.. hope you understand...

Last edited by Don Cragun; 06-07-2013 at 02:58 PM.. Reason: Added missing newlines to code segments.
 

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
All times are GMT -4. The time now is 08:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy