Shell script for running simultaneously two interfaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for running simultaneously two interfaces
# 1  
Old 09-08-2014
Shell script for running simultaneously two interfaces

Hi!

I have two environments on a machine and each one has some scripts for checking if some interfaces are down, and if so, it restarts them.

The issue now is that i cannot keep both interfaces running, on both environments i see the same process running.

How can i modify my scripts in order to reach that?

I have one script for checking if my .sh is running, and another one for restarting it (the first one calles the latter if it's down)

isRunning.sh is something like this:

Code:
ps -ef |grep -v grep |grep -v 'isProgRunning.sh'| grep -v 'stopProg.sh' |grep -v 'runProg.sh' |grep -v 'restartProg.sh'| grep -v 'ProgStopper' | grep 'XX:SurvivorRatio=4 -Xnoclassgc' >/dev/null 2>/dev/null

if [ $? -eq 0 ]
then
	echo ""
	echo "Process: " `ps -ef |grep -v grep |grep -v 'isProgRunning.sh'| grep -v 'stopProg.sh' |grep -v 'runProg.sh' |grep -v 'restartProg.sh'| grep -v 'ProgStopper' | grep 'XX:SurvivorRatio=4 -Xnoclassgc' | awk '{print $2}'`
	echo ""
	echo " is running"
	exit 0
else
	echo " is down"
	exit 1

fi

and the second sets a variable to hold the directory hierarchy from where it's executed, and it starts the interface, using nohup command.

what should i do?
# 2  
Old 09-08-2014
I in such case use a different UID when having 2 instances of the same program running to differenciate them (different UID - same GID with group set as -rws-on the directories ...)
# 3  
Old 09-08-2014
The traditional way to check if a process is running is PID files. When you start it, arrange for a file containing its PID to be created to reference later. This avoids the ps | awk | grep | sed | cut | kitchen | sink nonsense, and is a lot more portable, and allows you to run more than one of the same thing independently without them conflicting.

Code:
#!/bin/sh

# Often /var/run, but only root can write there
MYPIDFILE=/path/to/mypid.pid

if [ -f "$MYPIDFILE" ] && read -r PID "$PIDFILE" && ps "$PIDFILE" >/dev/null
then
          echo "Process is still running as PID $PID" >&2
          exit
fi

echo "Process is not running." >&2

# If your shell complains about 'disown', then your shell doesn't need it and it can be removed
/path/to/processtostart & disown # Assumes the process does not fork other PIDs

echo "$!" > "$MYPIDFILE"

echo "Now running as PID $!" >&2
exit

It's possible that your daemons are creating PID files somewhere already. Take a look around their files.
# 4  
Old 09-09-2014
What you are saying is to set a variable with the pid of my process and check if it's running based on that pid?

Would that alone solve the problem of parallel processes or do i have to combine this solution with the change of uid?

More specificly, on each of the environments i have this binary folder i have different scripts for verifying the processes, i mean i run them from different paths, being different scripts. They have the same permissions now. Each pair of isProgRunning and runProg to be in the same gid, but have different uid?

Last edited by Jane_Doe; 09-09-2014 at 09:23 AM..
# 5  
Old 09-09-2014
Quote:
Originally Posted by Jane_Doe
What you are saying is to set a variable with the pid of my process and check if it's running based on that pid?

Would that alone solve the problem of parallel processes or do i have to combine this solution with the change of uid?
No two programs will have the same PID while they're running.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

2. Shell Programming and Scripting

Run 2 shell scripts simultaneously from one script

i Run 2 scripts on all of around 50 nodes every day. 1.Mod_1.sh 2.Mod_2.sh eg.. i run file with specific node no like Mod_1.sh NODE_(node number) Mod_2.sh NODE_(node number) I want to run both file by using single script with unique node number. Eg.. Mod_new.sh NODE_(node... (11 Replies)
Discussion started by: Ganesh Mankar
11 Replies

3. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

4. Shell Programming and Scripting

Executing multiple ssh commands inside a shell simultaneously

I would like to execute a commands in four different servers through ssh at a single instance(simultaneously). Below are the details with examples, ssh user1@server1 "grep xxxx logs" ssh user1@server2 "grep xxxx logs" ssh user1@server3 "grep xxxx logs" Each statement will take some... (4 Replies)
Discussion started by: Amutha
4 Replies

5. Red Hat

Ssh error while two interfaces are up simultaneously

hi all, my system having two interfaces of 172.16.1.232 and 10.250.41.10 and i am using this to establish tunnel to our client network. eth0=10.250.41.10 eth1=172.16.1.232 I am not able to connect when two interfaces are up root@mind-41 ~]# ssh -l avytla 172.16.80.203 ssh:... (2 Replies)
Discussion started by: muzaffar.k
2 Replies

6. IP Networking

Eth interfaces UP but NOT RUNNING

Hi people, I have a solaris OS system. I configured its interfaces. They are UP but not in RUNNING status except loopback interface. I made the interfaces DOWN and UP again. The other side of the interfaces (switch ports) are UP. Does anyone have any idea? What may cause this problem, How can I... (1 Reply)
Discussion started by: hubatuwang
1 Replies

7. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

8. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies

9. Filesystems, Disks and Memory

Running 2 Drives simultaneously?

So I have yet another query which requires the genius of the users on Unix.com. Having asked around at my work (Tech company) No one can really answer my question thoroughly. My goal is to get 2 Hard drives running at the same time and allow me to switch between working on one to the other.... (4 Replies)
Discussion started by: Infidel
4 Replies

10. Solaris

Running 2 apaches simultaneously

Hello, I want to run 2 apaches simultaneusly in a system, one operating with port 80 and the other one with 85, i already have the configuration files ready and i tryed something i saw in a manual, like this: first i start apache as normal: /usr/local/etc/httpd/bin/apachectl start the i... (2 Replies)
Discussion started by: sx3v1l_1n51de
2 Replies
Login or Register to Ask a Question