Exec goes outside of loop


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Exec goes outside of loop
# 1  
Old 04-14-2014
Exec goes outside of loop

Hello all, I have an AIX 6.1 machine and i am having a hard time to figure out how i can make exec work inside a loop. i have a while loop which calls a case statement in it. when the user chooses a specific choice, it calls a script using exec. The reason that i use exec to run this script is because through this script it can open many windows so i do not want to have a lot of ksh running on my server. the problem is that when the user exits the script then it exits the shell. it does not go to the next line of the loop. Is there a way to have both the loop running and call the exec for executing my script or is it impossible? Thank you
# 2  
Old 04-14-2014
exec turns the current shell into the called processes, i.e. the current shell is gone.
Simply run the whatever program without exec!
The shell will wait until it exits; this is the behavior you intend.
# 3  
Old 04-14-2014
the problem is that if i run this program without exec, if a user runs 3 programs from the initial program then i see double processes on the server. 3 for the programs and another 3 that is for ksh because it starts a new shell. and this is what i am trying to avoid. there is no way for lets say exec call 2 programs? so when the first program will finish then it will call my second program which will re-launch the loop again.
# 4  
Old 04-14-2014
Is your system so overloaded that fork fails? If not, why fret? If so, you've got a bigger problem than a few instances of ksh.

Regards,
Alister
# 5  
Old 04-16-2014
well we are talking about a lot of users connecting to the system so it is better to try to minimize the load on it whenever possible. its better to build something right from the beginning and have more chances of keeping it up and running without problems rather just do something if is something happens then you try to find out what can you do
# 6  
Old 04-16-2014
Quote:
Originally Posted by omonoiatis9
there is no way for lets say exec call 2 programs? so when the first program will finish then it will call my second program which will re-launch the loop again.
Impossible. exec only accepts a single command.

If you believe that I am mistaken, refer yourself to the documentation of the exec system call interface which is wrapped by the exec shell builtin.

If you aren't sure about your script, post it. Vague concerns about instances of ksh in the process list is not a good reason to overcomplicate an implementation.

Regards,
Alister

Last edited by alister; 04-16-2014 at 11:55 AM..
# 7  
Old 04-16-2014
Quote:
Originally Posted by omonoiatis9
well we are talking about a lot of users connecting to the system so it is better to try to minimize the load on it whenever possible. its better to build something right from the beginning and have more chances of keeping it up and running without problems rather just do something if is something happens then you try to find out what can you do
exec reduces the number of processes by replacing your shell with something else. Once you exec, your shell is gone.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

2. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

3. UNIX for Advanced & Expert Users

Using -exec with and without -name

Hi, I need to delete the last N days file using find. I am trying to use find . -mtime -10 -print which lists down required files. but when i use find . -mtime -10 -exec ls -lrt {} \; it gives me all files in the directory including the required files but the required files... (7 Replies)
Discussion started by: v_m1986
7 Replies

4. Ubuntu

Find and EXEC

This is a huge issue. and I need it fixed ASAP. account-system gate-system race_traffic_sensor achievement-system global race_voicepack admin glue-system realdriveby admin-system gps realism-system... (5 Replies)
Discussion started by: austech360
5 Replies

5. UNIX for Dummies Questions & Answers

exec

Hi, i don't understand this part of one script exec >> $Log_File 2>&1 (1 Reply)
Discussion started by: messi777
1 Replies

6. UNIX for Advanced & Expert Users

-exec cp

Hi, on AIX 6.L I want to copy the result of grep -v to test directory then : `hostname`@oracle$ls -l | grep -v RINT -exec cp {} test grep: can't open -exec grep: can't open cp grep: can't open {} test:°`. Can you help me ? Thank you. (3 Replies)
Discussion started by: big123456
3 Replies

7. Shell Programming and Scripting

Help with use of `` vs exec

Hi all, I had an issue regarding use of `` or exec in perl . `` are considered to be unsafe. Why? In my case an user would be giving some parameters as input and I will form an command of it and execute it using ``. It is important to capture output as i have to parse the output. As well as I need... (0 Replies)
Discussion started by: bharadiaam
0 Replies

8. UNIX for Dummies Questions & Answers

Need help with -exec cp command.

I have a ksh script that contains the following: find /dir1/dir2 -type f -name "FILE.*" -newer /dir1/dir2/afterme.txt -exec cp /dir1/dir2/dir3 {} \; When I run it from the cli, it runs fine. When I run it from the ksh script I get find: missing argument to `-exec' I also tried -exec cp... (40 Replies)
Discussion started by: bbbngowc
40 Replies

9. UNIX for Advanced & Expert Users

exec

I have read that exec "replaces the current process with a new one". So I did $ exec ls and after this executed, my shell disappeared. I am assuming that my shell had PID xyz, and when I did exec ls, this ls got pid xyz, and when it terminated, there was no more shell process running, and... (5 Replies)
Discussion started by: JamesByars
5 Replies

10. Shell Programming and Scripting

exec

In exec function say when i would like to remove the files exec rm{}\; Why is this "\" needed immediately after {} and what if i dont give it? TIA, Nisha (1 Reply)
Discussion started by: Nisha
1 Replies
Login or Register to Ask a Question